Skip to Content

Scenario

Sometimes it is required to feed data from source fields which are of length > 60 into BW. In such cases while populating target fields into BW we get blank spaces.

Ex:

We have 3 source fields of length 100 and we want to populate fields in BW target.  We have entered 50 characters each in 3 fields of source system (total characters 150). Now we want 1st field in BW to have 60 characters and 2nd field to have 60 characters and 3rd field to have rest 30 characters.

Code needs to be written in two pieces, one in Start routine and other in end routine.

Source fields METRIC_HELP1, METRIC_HELP2 and METRIC_HELP3

Target fields /bic/zdbcmnt1, /bic/zdbcmnt2 and /bic/zdbcmnt3

 

Some declarations

 TYPES: BEGIN OF it_tab1,
      metric_id TYPE c LENGTH 4,
      comments TYPE c LENGTH 1500,
      END OF it_tab1.
DATA: it_tab2 TYPE STANDARD TABLE OF it_tab1,
          wa_tab2 TYPE it_tab1.

 

 

Start routine Code-METRIC_ID .  “Suppose key here is metric ID”<br />      if sy-subrc = 0 .
        CLEAR var_length.
        CLEAR v_string.
        CLEAR v_comment.

        
        if wa_tab-METRIC_HELP1 is NOT INITIAL.
          Var_Length = strlen( wa_tab-METRIC_HELP1 ) .
          v_comment = wa_tab-METRIC_HELP10(Var_Length).<br />          CONCATENATE v_string v_comment into v_string.<br />        ENdif.<br /><br /><br />        if wa_tab-METRIC_HELP2 is NOT INITIAL.<br />          CLEAR var_length.<br />          Var_Length = strlen( wa_tab-METRIC_HELP2 ) .<br />          v_comment = wa_tab-METRIC_HELP20(Var_Length).
          CONCATENATE v_string v_comment into v_string.
        endif.

        if wa_tab-METRIC_HELP3 is NOT INITIAL.
          CLEAR var_length.
          Var_Length = strlen( wa_tab-METRIC_HELP3 ) .
          v_comment = wa_tab-METRIC_HELP30(Var_Length).<br />          CONCATENATE v_string v_comment into v_string.<br />        ENDIF.</p><p>   WA_TAB2-COMMENTS = v_string.</p><p>   APPEND WA_TAB2 TO IT_TAB2.<br />        CLEAR WA_TAB2.<br />      ENDIF.<br /><br />    ENDLOOP.</p><p>End routine Code</p><p> LOOP AT it_tab2 INTO wa_tab2.<br />      READ TABLE RESULT_PACKAGE INTO wa_final<br />      WITH KEY /bic/zdbmtrid  = wa_tab2-metric_id.<br />      IF sy-subrc = 0 .<br />        var_length = STRLEN( wa_tab2-comments ) .<br />        IF wa_tab2-comments IS NOT INITIAL.<br />          var_quotient = var_length DIV 60.<br />          var_reminder = var_length MOD 60.<br />          IF var_quotient = 0.<br />            count = 0.<br />          ELSE .<br />            count = 1.<br />          ENDIF.<br />          n = var_quotient.<br /><br /><br />          DO n TIMES.<br /><br /><br />            CASE count.<br /><br />              WHEN 1.<br />                wa_final-/bic/zdbcmnt1 = wa_tab2-comments0(60).
              WHEN 2.
                wa_final-/bic/zdbcmnt2 = wa_tab2-comments60(60).<br />              WHEN 3.<br />                wa_final-/bic/zdbcmnt3 = wa_tab2-comments120(60).

ENDCASE.
    count = count + 1 

         ENDDO.

  CASE count .
            WHEN 0.

              wa_final-/bic/zdbcmnt1 = wa_tab2-comments0(var_reminder).<br />            WHEN 1.<br /><br />              wa_final-/bic/zdbcmnt1 = wa_tab2-comments0(var_reminder).
            WHEN 2.

              wa_final-/bic/zdbcmnt2 = wa_tab2-comments60(var_reminder)<br />                            .<br />            WHEN 3.<br />              wa_final-/bic/zdbcmnt3 =<br />              wa_tab2-comments120(var_reminder).

             ENDCASE.
        ENDIF.

MODIFY RESULT_PACKAGE FROM wa_final TRANSPORTING /bic/zdbcmnt1
        /bic/zdbcmnt2 /bic/zdbcmnt3

      ENDIF.
    ENDLOOP.

 

IT_TAB: internal table

wa_tab: work area of internal table

SOURCE_PACKAGE: Data in the source package

*RESULT_PACKAGE: * Data in the result package

wa_final: work area of result package

Variables used are of type integer:  var_length, v_string, v_comment, var_quotient , var_reminder , Count, n</p>

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply