Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

looping the internal table T_QMAT

Former Member
0 Kudos

Hi friends,

plz go through my code and provide me a solution for it.

DATA :

Begin of T_QMAT OCCURS 0,

LGNUM TYPE LTAP-LGNUM,

MATNR TYPE LTAP-MATNR,

WERKS TYPE LTAP-WERKS,

VLPLA TYPE LTAP-VLPLA,

END OF T_QMAT.

START-OF-SELECTION.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '021234'.

APPEND T_QMAT.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '031234'.

APPEND T_QMAT.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '041234'.

APPEND T_QMAT.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '051234'.

APPEND T_QMAT.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '061234'.

APPEND T_QMAT.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '071234'.

APPEND T_QMAT.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '081234'.

APPEND T_QMAT.

T_QMAT-LGNUM = 'ABC'.

T_QMAT-MATNR = '4545'.

T_QMAT-WERKS = '1000'.

T_QMAT-VLPLA = '091234'.

APPEND T_QMAT.

LOOP AT T_QMAT.

WRITE : /5 T_QMAT-LGNUM,

13 T_QMAT-MATNR,

20 T_QMAT-WERKS,

30 T_QMAT-VLPLA.

ENDLOOP.

OUTPUT :

ABC 4545 1000 021234

ABC 4545 1000 031234

ABC 4545 1000 041234

ABC 4545 1000 051234

ABC 4545 1000 061234

ABC 4545 1000 071234

ABC 4545 1000 081234

ABC 4545 1000 091234

now my requirement is when iam looping T_QMAT

i want to loop in my order based on the field VLPLA (source storage bin )

i want the loop to be done in this way.

output :

ABC 4545 1000 051234

ABC 4545 1000 081234

ABC 4545 1000 041234

ABC 4545 1000 021234

ABC 4545 1000 031234

ABC 4545 1000 071234

ABC 4545 1000 021234

ABC 4545 1000 061234

how can i do that.

Thanks in advance,

Regards,

priyanka

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Priyanka,

Output that you want to get is very difficult as you have three fields which are same. Only way you can get a diff output from the one that you are getting now is by sorting the internal table T_QMAT in a different way with field VLPLA. Try this. Try F1 help on sort command.

Thanks,

Jayant Sahu.

3 REPLIES 3

Former Member
0 Kudos

Hi Priyanka,

The loop will always occur from the first record to the last record.

You have not mentioned the requirent clearly.

Do you want it in sorted form ?

0 Kudos

swasthik i can sort the itab T_QMAT.

But i want the records to come into the header line as per my requiremnt.

actually as per sap standard configuration we get the values into that T_QMAT internal.

but my functional guys have changed the configuration.

as per the sap standard configuration the ist record of T_QMAT

is the record whic comes to header when looping and then 2nd record so on........ till 25th record.

but due to the changed configuration now the 5th record should come in to header first then the 7th record should come , then 9th record. etc so 0n...... as per there configuration.

To get the records as per the changed configuration there should be check done from T343J table

to perform the check i will get the values of T343J into another internal table say ITAB1.

And now while looping T_QMAT i should give a where condition but there is no field common in both T343j and T_QMAT table

how can i get that.

is it possible.

Regards,

priyanka.

Former Member
0 Kudos

Hello Priyanka,

Output that you want to get is very difficult as you have three fields which are same. Only way you can get a diff output from the one that you are getting now is by sorting the internal table T_QMAT in a different way with field VLPLA. Try this. Try F1 help on sort command.

Thanks,

Jayant Sahu.