Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8808

Re: Smartform printing based on Dynamic Data

$
0
0

Hi Shweta-

This is what I recommend: Rather than writing the logic in Smart Form -> Table/Template for determining which PO needs to be displayed like for PO1, PO2 and PO3.

What I would do is to create a new internal table with structure like below:

IT_FINAL:

Material     PO1     PO2     PO3

ABC          123     234     345

ABC          456     567

 

Now I would write logic (to build my final internal table as shown above) either in driver program or in Smart From -> Global Definitions -> initialization.

 

After above step you will knowing for a Material which PO needs to be displayed and where to be displayed.

 

Now next step is how to fill these PO details in Table / Template.

In your Smart Form -> Table make use of program lines to fetch details from Material table and PO table.

READ TABLE it_po INTO wa_po WITH KEY ebeln = wa_final-po1.

IF sy-sybrc = 0.

   "fill your text's in smartform

ENDIF.

In the same way you can fetch details for other PO's and you can display them in your text's.

 

Here is the code for building final internal table based on unique materials(it_matnr) and unique PO's(it_po).

 

TYPES: BEGIN OF t_matnr,

         matnr TYPE mara-matnr,

        END OF t_matnr,

 

        BEGIN OF t_po,

         matnr TYPE mara-matnr,

         ebeln TYPE ekko-ebeln,

        END OF t_po,

 

        BEGIN OF t_final,

          matnr TYPE mara-matnr,

          po1   TYPE ekko-ebeln,

          po2   TYPE ekko-ebeln,

          po3   TYPE ekko-ebeln,

        END OF t_final.

 

DATA: it_matnr TYPE STANDARD TABLE OF t_matnr,

       wa_matnr TYPE t_matnr,

       it_po    TYPE STANDARD TABLE OF t_po,

       wa_po    TYPE t_po,

       it_final TYPE STANDARD TABLE OF t_final,

       wa_final TYPE t_final.

 

CLEAR: wa_matnr.

wa_matnr = 'ABC'.

APPEND wa_matnr TO it_matnr.

 

CLEAR: wa_matnr.

wa_matnr = 'DEF'.

APPEND wa_matnr TO it_matnr.

 

CLEAR: wa_matnr.

wa_matnr = 'GHI'.

APPEND wa_matnr TO it_matnr.

 

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '123'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '234'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '345'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '456'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '567'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '678'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '789'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '890'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '901'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'GHI'.

wa_po-ebeln = '012'.

APPEND wa_po TO it_po.

 

CLEAR: wa_po.

wa_po-matnr = 'GHI'.

wa_po-ebeln = '001'.

APPEND wa_po TO it_po.

 

SORT : it_matnr BY matnr ASCENDING,

        it_po    BY matnr ASCENDING

                    ebeln ASCENDING.

 

LOOP AT it_matnr INTO wa_matnr.

*  CLEAR: wa_final.

   LOOP AT it_po INTO wa_po WHERE matnr = wa_matnr-matnr.

     IF sy-tabix NE 1.

       AT NEW matnr.

         APPEND wa_final TO it_final.

         CLEAR wa_final.

       ENDAT.

     ENDIF.

     wa_final-matnr = wa_matnr-matnr.

     IF wa_final-po1 IS INITIAL.

       wa_final-po1 = wa_po-ebeln.

       CONTINUE.

     ENDIF.

 

     IF wa_final-po2 IS INITIAL.

       wa_final-po2 = wa_po-ebeln.

       CONTINUE.

     ENDIF.

 

     IF wa_final-po3 IS INITIAL.

       wa_final-po3 = wa_po-ebeln.

       APPEND wa_final TO it_final.

       CLEAR wa_final.

     ENDIF.

 

   ENDLOOP.

   APPEND wa_final TO it_final.

ENDLOOP.

 

DELETE ADJACENT DUPLICATES FROM it_final COMPARING ALL FIELDS.

 

IF it_final IS NOT INITIAL.

   LOOP AT it_final INTO wa_final.

     WRITE: / wa_final-matnr, wa_final-po1, wa_final-po2, wa_final-po3.

   ENDLOOP.

ENDIF.

 

Output:

Capture.JPG

I'm sorry for writing such a long story...:)

 

-Venkat


Viewing all articles
Browse latest Browse all 8808

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>