Skip to Content
-1

Endroutine - Lookup to derive multiple values

May 07 at 10:16 AM

42

avatar image

Hi,

I am not able to derive multiple values with below code. My requirement is to derive to a lookup to the material master data table and derive all materials where the first 7 characters match with the input file material .


* declaring material table
DATA: Z_MATERIAL TYPE STANDARD TABLE OF /BI0/PMATERIAL.
FIELD-SYMBOLS: <Z_MATERIAL> LIKE LINE OF Z_MATERIAL.
* selecting data from material table
SELECT * FROM /BI0/PMATERIAL INTO CORRESPONDING FIELDS OF TABLE
 Z_MATERIAL WHERE OBJVERS = 'A'.

Types: ty_data type _ty_s_TG_1.
Data: t_data type STANDARD TABLE OF ty_data,
      w_data type ty_data,
      l_tabix type sy-tabix,
      l_line type I.

clear: l_tabix, w_data.
BREAK-POINT.
t_data[] = RESULT_PACKAGE[].
loop at t_data into w_data.
       l_tabix = sy-tabix.
       l_line = l_line + 1.
 LOOP AT Z_MATERIAL ASSIGNING <Z_MATERIAL>
  WHERE MATERIAL+0(7) = w_data-MATERIAL.
       clear w_data.
        W_DATA-MATERIAL = <Z_MATERIAL>-MATERIAL.
        W_DATA-TYPE= <RESULT_FIELDS>-TYPE.

        W_DATA-RECORD  = l_line.
        APPEND  <RESULT_FIELDS> TO T_DATA.
ENDLOOP.
endloop. " Result_package

RESULT_PACKAGE[] = t_data[].

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Mario Tibollo May 07 at 11:33 AM
0

what's the final goal of the code? you can't add all the materials you'll find to the same result package record. So please elaborate on the requirements.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi,

My requirement is to loop through the Material table and derive all materials where the first 7 characters match with the material from input file as shown in the attached image. The end result is that I should get more materials as outcome.

Below is my Start routine code for selection of materials.

TYPES: BEGIN OF MAT_STRUCT,

      MATERIAL Type /BI0/OIMATERIAL,

      MAT_NEW(7) type c,

  END OF MAT_STRUCT.



  DATA: I_MAT TYPE SORTED TABLE OF MAT_STRUCT WITH UNIQUE KEY MATERIAL.

        FIELD-SYMBOLS: <GT_MAT> LIKE LINE OF I_MAT.



SELECT * FROM /BI0/PMATERIAL INTO CORRESPONDING FIELDS OF TABLE
 GT_MATERIAL WHERE OBJVERS = 'A'.
SELECT MATERIAL FROM /BI0/PMATERIAL INTO CORRESPONDING FIELDS OF TABLE I_MAT WHERE OBJVERS = 'A'.
LOOP AT I_MAT ASSIGNING <GT_MAT>. *CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' *EXPORTING * input = <GT_MAT>-MATERIAL *IMPORTING * output = <GT_MAT>-MATERIAL.
<GT_MAT>-MAT_NEW = <GT_MAT>-MATERIAL(7).

ENDLOOP.

END ROUTINE Logic to loop through the result package

DATA: E_S_RESULT TYPE _Ty_s_TG_1.
DATA: E_T_RESULT TYPE _Ty_t_TG_1.
Data: l_tabix type sy-tabix,
l_line type I.

*E_T_RESULT[] = RESULT_PACKAGE[].
*
BREAK-POINT.
LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.
*
* LOOP AT GT_MATERIAL ASSIGNING <GT_MATERIAL>
* WHERE MATERIAL+0(7) = <RESULT_FIELDS>-MATERIAL.
LOOP AT I_MAT ASSIGNING <GT_MAT> WHERE MAT_NEW =
<RESULT_FIELDS>-MATERIAL.
CLEAR: E_S_RESULT.
l_tabix = sy-tabix.
* l_line = l_line + 1.
l_line = 1.
BREAK-POINT.

<RESULT_FIELDS>-MATERIAL = <GT_MAT>-MATERIAL.
<RESULT_FIELDS>-FISCYEAR = E_S_RESULT-FISCYEAR.
<RESULT_FIELDS>-FISCVARNT = E_S_RESULT-FISCVARNT.
<RESULT_FIELDS>-CURRENCY = E_S_RESULT-CURRENCY.
<RESULT_FIELDS>-VTYPE = E_S_RESULT-VTYPE.
*<RESULT_FIELDS>-RECORD = l_line.
APPEND <RESULT_FIELDS> TO E_T_RESULT.
l_line = l_line + 1.

ENDLOOP.
ENDLOOP.
REFRESH RESULT_PACKAGE.
RESULT_PACKAGE[] = E_T_RESULT[].
*MOVE E_T_RESULT[] TO RESULT_PACKAGE[].
0
Rajkumar Narasimman May 07 at 11:50 AM
0

Hi Bhat,

"I am not able to derive multiple values with below code

You should always mention the problem which you are facing when you are composing the thread.

After saw your code, I found that you are looping and appending the same internal table T_DATA like below.

loopat t_data into w_data.
 LOOP AT Z_MATERIAL ASSIGNING <Z_MATERIAL>
        APPEND  <RESULT_FIELDS> TO T_DATA.
ENDLOOP.
endloop. " Result_package

In append statement, Instead of T_DATA use some other table like T_RESULT.

Regards

Rajkumar Narasimman

Share
10 |10000 characters needed characters left characters exceeded
Anand Kumar May 07 at 12:29 PM
0

HI,

use If condition in the loop statement:

t_data[]= RESULT_PACKAGE[].loopat t_data into w_data.
       l_tabix =sy-tabix.
       l_line = l_line +1.

LOOPAT Z_MATERIAL ASSIGNING<Z_MATERIAL.

   IF  MATERIAL+0(7)= w_data-MATERIAL+0(7).
*User other ABAP Key Words like SEARCH or CA OR FIRST OCCURRENCE OF
        <Z_MATERIAL>-MATERIAL = W_DATA-MATERIAL .
        <RESULT_FIELDS>-TYPE = W_DATA-TYPE.
        W_DATA-RECORD  = l_line.

APPEND<RESULT_FIELDS>TO T_DATA.

ENDIF
Clear w_data.
ENDLOOP.
Share
10 |10000 characters needed characters left characters exceeded