Application Development and Automation 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: 
Read only

Smartform printing based on Dynamic Data

Former Member
0 Likes
10,825

Dear All,

i am new to ABAP, now i have to create a smartform in which i have created a page

having a main window, in the main window i have created a template and a table,

my problem is that, i can show only three sets of data per page,

But as in a PR, there may be many sets of data (PO) ocuurs (lets say there are 8 sets of data),

so i wants to show all these 8 sets of data in my smartform.

One more thing is that, i have 2 internal table in which first table have unique materils and second table

have unique PO. So i have to print unique materials in row of my smartform and unique PO should be shown

as column in my smartforms.

So please see my issue, and sujjest me how can i code and call my smartform to show all PO's value.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

former_member187748
Active Contributor
0 Likes
8,311

Hi Shweta,

based on your requirement please check this,

lets say

it_final -> having all the data for your PO

it_final1-> having uniuqe PO

it_final2 -> having unique material

Now when you will pick unique material, in that internal table you may not have all the PO's values.

LOOP AT it_final2 INTO wa_final2.

READ TABLE it_final1 INDEX 1.

LOOP AT it_final INTO wa_final WHERE ebeln = it_final1-ebeln

                                                            matnr = wa_final2-matnr.

IF sy-subrc = 0

wa_final2-ebeln = wa_final-ebeln.

*

*

*

put all your data in wa_final as same as i have done for ebeln.

Modify it_final2 FROM wa_final2 TRANSPORTING ebeln............

ENDIF.

ENDLOOP.

ENDLOOP.

Do it for all index upto your internal table and pass it to your smartform ,


39 REPLIES 39
Read only

venkateswaran_k
Active Contributor
0 Likes
8,230

Hi Shweta

Can you please give some example, I am not able to understand the requirement.

Prefereably with screenshots

Regards,

Venkat

Read only

0 Likes
8,230

Dear Venkateswaran,

please see these table , these are the final output for my smartforms.Lets say in my first page

i am showing first 3 PO,s value

Material Des.
PO 1
PO2
PO3
Material 1PO1's valuesPO2's valuesPO3's values
Material 2PO1's valuesPO2's valuesPO3's values
Material 3PO1's valuesPO2's valuesPO3's values
Material 4PO1's valuesPO2's valuesPO3's values

and for remaining PO's values, which i wants to show should appear after this as in next page.

Material Des.
PO4
PO5
PO6
Material 1PO4 valuesPO5's valuesPO6's values
Material 2PO4's valuesPO5's valuesPO6's values
Material 3PO4's valuesPO5's valuesPO6's values
Material 4

for which i have created two internal table, one having materials (unique values), and other having unique PO

values, and one having all the values related to all PO's (obvious, because the table having unique material

should not have all PO's values and vice versa). Now as i can show only 3 PO's at once, please tell me how could i fetch

the data and put in the same table in my smartform(which has been used to show first 3 PO's values).

Please do the needful.

Read only

thangam_perumal
Contributor
0 Likes
8,230

Dear Shweta Chouhan,

                              Create the Table Inside the Loop in Smartforms.

consider internal Table name Itab_Mat and Work Area Wa_Mat which have details of Material.

                                           Itab_Po and Work area wa_Po Which have details of Po.

keep mind there is common field should be available for both internal Table.

consider Material field Name is Matnr.

After Creating Loop and Table Please Refer My Below Screen Shots.

Please try in this method.. it may help u..

Regards,

     Thangam

Read only

venkat_aileni
Contributor
0 Likes
8,230

Hi-

For question 1 to display only 3 line items per page you can make use of Page Break concept.

Steps to achieve the same:

Create a program line in your table with code like below:

lv_cnt = lv_cnt + 1.

Then create a command with condition lv_cnt = 3 and set Go to New Page option to next page.

Create a Program Line inside your command and clear variable lv_cnt.

For question 2:

Table1 -> Material.

Table2 -> PO

You would like to display Po's based on Materials.

Create a loop on table1 where you will be displaying Materials and you can make use of loop/table to display table2 with condition material = table1-material.

-Venkat

Read only

0 Likes
8,230

Dear Venkat,

i didn't wants to show 3 line items, but i have to show 3 PO's values in my smartforms in one page,and

remaining others should come in next pages in the multiple of 3.

Lets say i have 7 PO to be shown, my question is that, as i have shown first three PO's values, so

how could i show my remaining PO's values, that is to be printed when my first page values gets printed

and so on...and this process goes on untill i am able to print all PO's data.

Read only

0 Likes
8,230

Hello Shweta-

The simpler way which I feel is to build a final internal table with details like below:

IT_FINAL:

Material     PO1     PO2     PO3

ABC          123     234     345

ABC          456     567

In your driver program or in smartform initialization build above table based on your material and PO table details.

Then you can loop over this final internal table and you can fetch details from material and PO tables and display them accordingly.

-Venkat

Read only

0 Likes
8,230

Hi Venkat,

Let me clear more about it, say i have 7 PO and its related values as you can see below,

now if i have shown first 3 PO's values, say PO1, PO2, PO3, then i wants to know that when i wnats

to print another PO's like PO4, PO5 and PO6 values in smartform , should i have to use seperate variable for it, or i can use previous defined values, can you provide some code for the same,

it would be more advantage for me.

Material     PO1               PO2               PO3               PO4               PO5          PO6          PO7

ABC          1   2   3            2  3  4            3  4  5          1  2  3          2  4  5           2  5  4       9  8  6

ABC          4  5   6             5  6  7          1   2   3           2  5  4

Read only

0 Likes
8,229

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:


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

-Venkat

Read only

0 Likes
8,229

Dear Venkat,

thanks a lot for your support, let me clear one more thing before proceeding your ways,

First thing is that i have to show many data related to every PO.

As you have shown the output, i don't have such requirement, as you are showing,

ABC then again ABC, its not so, actually i have only one ABC in material (unique material)

and then its corresponding PO's, but as i told you that let i have shown correctly 3 PO's values

now using the same table in my smartform , i just wants to know how could i show another

PO's values. This is your output...........

But my output should be as shown below (say for first page)

ABC          123          234             345

DEF           678         789              890

GHI            167          774             321

and in second page

ABC          456          567

DEF          901

GHI

so please consider these output and then tell me the changes, i will appreciate your

sujjestion.....and thanks a lot again for helping me.

Read only

0 Likes
8,228

Hi Shweta-

Good requirement!!

Use below sample code for table alignment:

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,

       it_final_temp TYPE STANDARD TABLE OF t_final,

       wa_final_temp TYPE t_final.

DATA: lv_mat_cnt  TYPE i,

       lv_do       TYPE p DECIMALS 2,

       lv_line_cnt TYPE i,

       lv_tabix    TYPE sy-tabix.

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.

SORT it_final BY matnr ASCENDING

                  po1   ASCENDING

                  po2   ASCENDING

                  po3   ASCENDING.

lv_mat_cnt = lines( it_matnr ).

lv_line_cnt = lines( it_final ).

lv_do = lv_line_cnt / lv_mat_cnt.

lv_do = ceil( lv_do ).

DO lv_do TIMES.

   LOOP AT it_matnr INTO wa_matnr.

     LOOP AT it_final INTO wa_final WHERE matnr = wa_matnr-matnr.

       CLEAR: wa_final_temp.

       wa_final_temp = wa_final.

       AT NEW matnr.

         APPEND wa_final_temp TO it_final_temp.

         lv_tabix = sy-tabix.

       ENDAT.

     ENDLOOP.

     IF lv_tabix IS NOT INITIAL.

       DELETE it_final INDEX lv_tabix.

       CLEAR lv_tabix.

     ENDIF.

   ENDLOOP.

ENDDO.

IF it_final_temp IS NOT INITIAL.

   LOOP AT it_final_temp INTO wa_final.

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

   ENDLOOP.

ENDIF.

Output:

-Venkat

Read only

0 Likes
8,228

Dear Venkat,

thanks a lot for your sujjestions, i am not getting your points clearly so i am giving you this data.

Lets i have three internal tables

it_matnr -> having unique material no. (it may have any no of materials) ,

it_po   -> having unique PO's values(any no of PO)

it_all -> having data for all PO, and for its line items(means having all PO's and all material values,)

Now, as i don't know how many line items will be there for materials, so i can't do like this

as you have sujjested

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.

So i think , i have to write my code as shown below,


LOOP AT  it_matnr INTO wa_matnr.
 
   READ TABLE IT_PO  INDEX 1.
   LOOP AT IT_ALL  INTO WA_ALL WHERE EBELN = IT_PO-EBELN
                                       AND MATNR = WA_MATNR-MATNR.

IF SY-SUBRC = 0.

*********************

i have to put my data in new internal table from it_all.

so that by itterating , i will get all material values for each ebeln accordingly.

*************************

ENDIF.

ENDLOOP.

ENDLOOP.

and doing the same way for INDEX 2 and INDEX 3 for PO's table i have segregate it for 3 PO's values,

which i am able to show correctly, but after that, i am not getting what to do next.

In the same way , i can get all my data, but the question is how can i show these data after 3 PO's value

in my smartforms.

So please tell me is this a right way to achieve the target, because what you are sujjesting , i am not getting

it upto the mark.

Read only

0 Likes
8,228

Hello Shweta-

Please try to understand the logic first then it will be easy for you to design your Smart Form later.

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.

I have added above code just to populate data you don't need to do this.

-> We need only it_matnr and it_all data to design final internal table.

-> In our new logic I have changed it_final field length of po1, po2, po3 from 10 to 15.(so that you will be storing both po and line item together and while displaying data in your smart form you can differentiate for po which line item needs to be displayed hope this is clear).

Sample Code:

TYPES: BEGIN OF t_matnr,

         matnr TYPE mara-matnr,

        END OF t_matnr,

        BEGIN OF t_po,

         matnr TYPE mara-matnr,

         ebeln TYPE ekpo-ebeln,

         ebelp TYPE ekpo-ebelp,

        END OF t_po,

        BEGIN OF t_final,

          matnr TYPE mara-matnr,

          po1   TYPE char15,

          po2   TYPE char15,

          po3   TYPE char15,

        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,

       it_final_temp TYPE STANDARD TABLE OF t_final,

       wa_final_temp TYPE t_final.

DATA: lv_mat_cnt  TYPE i,

       lv_do       TYPE p DECIMALS 2,

       lv_line_cnt TYPE i,

       lv_tabix    TYPE sy-tabix.

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'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '234'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '345'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '456'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'ABC'.

wa_po-ebeln = '567'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '678'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '789'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '890'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'DEF'.

wa_po-ebeln = '901'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'GHI'.

wa_po-ebeln = '012'.

wa_po-ebelp = '00001'.

APPEND wa_po TO it_po.

CLEAR: wa_po.

wa_po-matnr = 'GHI'.

wa_po-ebeln = '001'.

wa_po-ebelp = '00001'.

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.

       CONCATENATE wa_po-ebeln wa_po-ebelp INTO wa_final-po1.

       CONTINUE.

     ENDIF.

     IF wa_final-po2 IS INITIAL.

       CONCATENATE wa_po-ebeln wa_po-ebelp INTO wa_final-po2.

       CONTINUE.

     ENDIF.

     IF wa_final-po3 IS INITIAL.

       CONCATENATE wa_po-ebeln wa_po-ebelp INTO wa_final-po3.

       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.

SORT it_final BY matnr ASCENDING

                  po1   ASCENDING

                  po2   ASCENDING

                  po3   ASCENDING.

lv_mat_cnt = lines( it_matnr ).

lv_line_cnt = lines( it_final ).

lv_do = lv_line_cnt / lv_mat_cnt.

lv_do = ceil( lv_do ).

DO lv_do TIMES.

   LOOP AT it_matnr INTO wa_matnr.

     LOOP AT it_final INTO wa_final WHERE matnr = wa_matnr-matnr.

       CLEAR: wa_final_temp.

       wa_final_temp = wa_final.

       AT NEW matnr.

         APPEND wa_final_temp TO it_final_temp.

         lv_tabix = sy-tabix.

       ENDAT.

     ENDLOOP.

     IF lv_tabix IS NOT INITIAL.

       DELETE it_final INDEX lv_tabix.

       CLEAR lv_tabix.

     ENDIF.

   ENDLOOP.

ENDDO.

IF it_final_temp IS NOT INITIAL.

   LOOP AT it_final_temp INTO wa_final.

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

   ENDLOOP.

ENDIF.

Output:


So now your po1 field will be PO Number + PO line Item.

In your smart form retrieve data based on PO and its corresponding line item.

Use above logic this will definitely work.

-Venkat


Read only

0 Likes
8,228

Hi Venkat,

can i have two Main window in single smartforms having in a different pages ?

If yes then how can i call my second page only if it is having any values to be displayed

otherwise my second page should not be called.

Have you done it ever  ?

If yes please sujjest me how can i do that.

Means if i will show 3 PO in first page and next in second page having again a main window

so can i restrict my second page for not getting displayed if it has no data for second page.

Please tell me about this scenario also.

I am using EHP5 , and i have heard that i can use more than two window in latest version.

Read only

0 Likes
8,228

Hi Shweta-

This is what I would suggest: Go step by step first get all the data and display it then look for data alignment on pages else there will be lot of confusion.

-> Does both your page1 and page2 looks alike? If so no need to create a new page in your page1 -> general Attributes select next page as first page itself.

-> If both pages doesn't look alike and you want to display page2 only if data is available then you have to create a command in your table->main area pointing to next page with a condition.

Refer below to know more details about how command works:

COMMAND in Smart Forms

-Venkat

Read only

0 Likes
8,228

Hi Venkat,

the example you have shown is meant for displaying results on pages based on no. of rows,

but i need to restrict calling my smartforms based on no of columns (3 per page.).

And till now what i have done is that, i have taken separate variable for each PO's related values,

so its becomes a tedious task for me.

Here i am sending you my smartform xml file, in which i have made it for 4 PO on each page

but you can see, how much variable i have to use within this, and in this way it becomes too

much tough to maintain.

Here are details regarding my smartforms.

it_bid - unique material

it_bid2_temp - unique PO

it_bidding - having all values for all ebeln and all materials

Now i have used two other pages and within this i just wants to restrict calling of second or third

page if it has no value to be displayed.

Please do needful, because i don't know how can i use command based on column values.

Read only

0 Likes
8,228

Hi Shweta-

The example which I had given is to just illustrate how command line works and it has got nothing to do with your requirement.

Kindly follow below steps you will definitely get the solution:

Step 1: We will be building our Final internal table in Smart Form -> Global Definitions -> Initialization Part.

Step 2: We will display the details on Form like 1 Material in a row and 3 PO's in column.

Step 3: We will align displaying Materials per page according to your requirement.

Now I will be explaining Step 1 and Step 2, once you are done with these then you can go for Form alignment.

Please make a copy of your existing Smart Form and delete everything under your Main window.

Step 1:

I am assuming that you are already having data in it_bid(Material) and it_bidding(PO and Materials combination).

* Create a Types declaration in your Global Definitions -> Types like below:

TYPEs:BEGIN OF t_final,

           matnr TYPE mara-matnr,

           po1   TYPE char15,

           po2   TYPE char15,

           po3   TYPE char15,

           END OF t_final.

-> Create an internal table and work area/structure in Global data by referring t_final like it_final and wa_final.

-> In your Form Initialization make use of logic which I have given in last to last reply. In that logic replace it_matnr internal table by it_bid and it_po by it_bidding.

-> After above step we will be done with our Step 1 i.e.filling of it_final internal table.

Step 2:

Please create 3 structures(will be displayed in columns) with the details which you want to display in columns say lwa_po1, lwa_po2 and lwa_po3.

Create a Table under your Main Window with loop on Internal table it_final.

-> Design your table accordingly...

-> Create a Program line under your table -> Main Area ->

Here what we will be doing is from our internal table we know for which material(in row) we are going to display data and also we know what are all the PO's we are going to display in columns.

So will be using READ statements to read details of each PO's (PO1, PO2 and PO3) from it_bidding and will be populating the same into the respective columns.

Use below sample code to populate data into 3 structures:

CLEAR lwa_po1.

READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln = wa_final-po1+0(10)

                                                ebelp = wa_final-po1+10(5).

IF sy-subrc = 0.

   MOVE-CORRESPONDING wa_bidding TO lwa_po1.

ENDIF.

CLEAR lwa_po2.

READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln = wa_final-po2+0(10)

                                                ebelp = wa_final-po2+10(5).

IF sy-subrc = 0.

   MOVE-CORRESPONDING wa_bidding TO lwa_po2.

ENDIF.

CLEAR lwa_po3.

READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln = wa_final-po3+0(10)

                                                ebelp = wa_final-po3+10(5).

IF sy-subrc = 0.

   MOVE-CORRESPONDING wa_bidding TO lwa_po3.

ENDIF.

-> Now populate these 3 structures data into your table columns like below:

Material                    Column 1:               Column 2               Column 3    

&lwa_po1-matnr&     &lwa_po1-ebeln&     &lwa_po2-ebeln&     &lwa_po3-ebeln&

                              &lwa_po1-ebelp&     &lwa_po2-ebeln&     &lwa_po3-ebeln&


Now after above steps we are done with Step 2 i.e. populating data into form. Please follow above approach step by step, It took almost 45 minutes to explain these steps....

-Venkat

Read only

0 Likes
8,228

Dear Venakt,

when i am writing these code lines as you have sujjested, i am getting error that "it_bidding2 may not be converted into a number"

lv_mat_cnt = lines(it_bidding2).
lv_line_cnt = lines(it_final).
lv_do = lv_line_cnt / lv_mat_cnt.
lv_do = cell(lv_do).

Read only

0 Likes
8,228

Hi-

Please try like below:

lv_mat_cnt = lines( it_bidding2[] ).
lv_line_cnt = lines( it_final[] ).

Please take care of spaces...

-Venkat

Read only

0 Likes
8,228

Dear Venkat,

i have created 3 structure namely lwa_po1, lwa_po2, lwa_po3 and also declared a work area

wa_po1, wa_po2, wa_po3 respectively for my column field whom data is to be filled in main table.

And also i have created a structure

TYPES : BEGIN OF TY_FINAL,
         EMATN TYPE ZIT_BIDDING-EMATN,
         PO1 TYPE ZIT_BIDDING-PO,
         PO2 TYPE ZIT_BIDDING-PO,
         PO3 TYPE ZIT_BIDDING-PO,
END OF TY_FINAL.

But when i have written these code lines, it gives error as "

The data object "WA_FINAL-PO1" has no structure and therefore no component called "EBELP".

where as my code is as shown below, please tell me where i am wrong.

SORT : it_bidding2 BY ematn ASCENDING,
        it_bidding BY ebeln ASCENDING
                      EMATN ASCENDING.

LOOP AT it_bidding2 INTO wa_bidding2.
   CLEAR : WA_FINAL.
   LOOP AT it_bidding INTO wa_bidding WHERE ematn = wa_bidding2-ematn.
     IF SY-TABIX NE 1.
       AT NEW ematn.
         APPEND wa_final TO it_final.
         CLEAR : wa_final.
       ENDAT.
     ENDIF.

     wa_final-ematn = wa_bidding2-ematn.

     IF wa_final-PO1 IS INITIAL.
       CONCATENATE wa_bidding-ebeln wa_bidding-ebelp INTO wa_final-PO1.
       CONTINUE.
     ENDIF.

     IF wa_final-PO2 IS INITIAL.
       CONCATENATE wa_bidding-ebeln wa_bidding-ebelp INTO wa_final-PO2.
       CONTINUE.
     ENDIF.

     IF wa_final-PO3 IS INITIAL.
       CONCATENATE wa_bidding-ebeln wa_bidding-ebelp INTO wa_final-PO3.
       APPEND wa_final TO it_final.
       CLEAR : wa_final.
     ENDIF.
   ENDLOOP.
   APPEND wa_final TO it_final.
ENDLOOP.

BREAK abap.
DELETE ADJACENT DUPLICATES FROM it_final COMPARING ALL FIELDS.

SORT: it_final BY ematn ASCENDING
       PO1 ASCENDING
       PO2 ASCENDING
       PO3 ASCENDING.

lv_mat_cnt = lines( it_bidding2[] ).
lv_line_cnt = lines( it_final[] ).
lv_do = lv_line_cnt / lv_mat_cnt.
lv_do = ceil( lv_do ).

DO lv_do TIMES.
   LOOP AT it_bidding2 INTO wa_bidding2 .
     LOOP AT it_final INTO wa_final WHERE ematn = wa_bidding2-ematn.
       CLEAR : wa_final_temp .
       wa_final_temp = wa_final.
       AT NEW ematn.
         APPEND wa_final_temp TO it_final_temp.
         lv_tabix = sy-tabix.
       ENDAT.
     ENDLOOP.

     IF lv_tabix IS NOT INITIAL.
       DELETE it_final INDEX lv_tabix.
       CLEAR : lv_tabix.
     ENDIF.
   ENDLOOP.
ENDDO.

IF it_final_temp IS NOT INITIAL.
   LOOP AT it_final_temp INTO wa_final_temp .
     WRITE : / wa_final_temp-ematn, wa_final_temp-PO1, wa_final_temp-PO2,
     wa_final_temp-PO3.
   ENDLOOP.
ENDIF.

CLEAR  wa_po1.
READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln = wa_final-po1+0(10)
                                   ebelp = wa_final-po1-ebelp+10(5).
IF SY-SUBRC = 0.
   MOVE-CORRESPONDING wa_bidding TO wa_po1.
ENDIF.

CLEAR : wa_po2.
READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln = wa_final-po2+0(10)
                                   ebelp = wa_final-po2-ebelp+10(5).
IF SY-SUBRC = 0.
   MOVE-CORRESPONDING wa_bidding TO wa_po2.
ENDIF.

CLEAR : wa_po3.
READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln = wa_final-po3+0(10)
                                   ebelp = wa_final-po3-ebelp+10(5).
IF SY-SUBRC = 0.
   MOVE-CORRESPONDING wa_bidding TO wa_po3.
ENDIF.

"

Read only

0 Likes
8,228

Hi-

Please replace your READ statement content with below:

CLEAR  wa_po1.

READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln= wa_final-po1+0(10)

                                   ebelp = wa_final-po1+10(5).

IF SY-SUBRC = 0.

   MOVE-CORRESPONDING wa_bidding TO wa_po1.

ENDIF.


CLEAR : wa_po2.

READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln= wa_final-po2+0(10)

                                   ebelp = wa_final-po2+10(5).

IF SY-SUBRC = 0.

   MOVE-CORRESPONDING wa_bidding TO wa_po2.

ENDIF.


CLEAR : wa_po3.

READ TABLE it_bidding INTO wa_bidding WITH KEY ebeln= wa_final-po3+0(10)

                                   ebelp = wa_final-po3+10(5).

IF SY-SUBRC = 0.

   MOVE-CORRESPONDING wa_bidding TO wa_po3.

ENDIF.

Also exclude these statements I have written this just to show output using write statement.

IF it_final_temp IS NOT INITIAL.

   LOOP AT it_final_temp INTO wa_final_temp .

     WRITE : / wa_final_temp-ematn, wa_final_temp-PO1,wa_final_temp-PO2,

     wa_final_temp-PO3.

   ENDLOOP.

ENDIF.

-Venkat

Read only

former_member187748
Active Contributor
0 Likes
8,312

Hi Shweta,

based on your requirement please check this,

lets say

it_final -> having all the data for your PO

it_final1-> having uniuqe PO

it_final2 -> having unique material

Now when you will pick unique material, in that internal table you may not have all the PO's values.

LOOP AT it_final2 INTO wa_final2.

READ TABLE it_final1 INDEX 1.

LOOP AT it_final INTO wa_final WHERE ebeln = it_final1-ebeln

                                                            matnr = wa_final2-matnr.

IF sy-subrc = 0

wa_final2-ebeln = wa_final-ebeln.

*

*

*

put all your data in wa_final as same as i have done for ebeln.

Modify it_final2 FROM wa_final2 TRANSPORTING ebeln............

ENDIF.

ENDLOOP.

ENDLOOP.

Do it for all index upto your internal table and pass it to your smartform ,


Read only

0 Likes
8,228

Dear Sanjeev,

i have segregate my data as you told, and as you can see i am showing mine 3 PO's values

in first page, now the matter is that, when i will fill once me page with these 3 PO's values,

then to show the remaining PO's value how could i fetch my internal table and i can show

remaining data.

Read only

0 Likes
8,228

Hi,
you can create two pages, and create one table each in main window. in first page, fetch value from your itable and pring what are the fields you want, and do the same for second page also.

and regarding how to fetch values, i would like to know how did you define your ineternal table and what are the fields in each table and what are the fields you needed to print,

Read only

0 Likes
8,228

Hi Sebin,

if i will create another page, then what type of window it will have, if i will use secondary window

then i can't take it for next page, i can't use secondary window because it may not having such

flexibility as we finds in main window, i can't use copies window too, because my second page

having different data from my first page.

One more thing is that, if i will use second page then my smartform will always print for two pages

irrespective of data it has, means if i have only one PO's value to be print then still, it will print two pages, with my one PO's values..........

I have already used this concept, but not succeeded, due to the problem i stated to you.

Read only

0 Likes
8,228

hi,

you can create two pages, and do not use seconday windows as it will not expand according to the data you are displaying.

you can have one main window in each pages(not in the same pages), but make sure the size of all the main windows are same, else it will generate error,


reagarding printing, yes you are right.  you would always get two pages and i guess thats what you exactly asked for, one unique material and some 'po's in one page and the same material with deifferent po in another page,

(for this you may check if a material has got more than 3 'PO's if yes, do pass data to the second main window. and give your conditions at the tab 'conditions')

according to

Read only

0 Likes
8,228

Hi Sebin,

you are right i have to show some material and some PO in first page and with same material and remaining PO's in next page, but i have again two questions here.

1. It is possible to have more than one main window in one smartform ?.

2. If i will make second page then how could i call my second page, because i can't call

second page having main window as usual.

(so have you used before the main window second time in a smartform ? )

Read only

0 Likes
8,228

hi ,

1.its possible to have more than one main windows in single smartform but you cant use more than one window in same page.

i.e only one main window is allowed for one page, make sure you give same width, height and size for all the main windows in your smartform.

2. yes, i have done this before, i had created two pages with main windows each on them( for appointment letter printing, used standard text so10 on first page and salary tabulation in second page) it worked well and moved to production server.

  reagrding calls to the 2nd page,
1.double click on your first page

2.click tab 'general attributs'

3.select 'next page' and give your 2nd page name

save and activate.

cheers!

Read only

0 Likes
8,228

Hi Sebin,

but i have a question for you,

if i will create second page, then my smartform will always display second page,

so can i restrict my second page printing, if i don't have data to show on second page.

Lets say for any PR i have only one PO to display, so can i restrict my second page calling.

Read only

0 Likes
8,228

hi,

If the data will be held in the first page itself, then normally it will not flow to the second page until and unless you forcefully make it.

make sure you have one main window only in the second page, no logo, no other window etc.

in that case it automatically restricts the second page from printing.
if its not restricted, double click on the main window on the second page,

select 'Conditions' tab and give some conditions.

or right click the 2nd main window, create-> flowlogic->command
then give the necessary conditions overe there

note : make sure that you are working on new release of SAP, else we cant give two main windows,
to check your release, goto ant tcode,
from the meny bar, select 'System' ->status and check for the version or you ask colleague if you are using new versions

Read only

0 Likes
8,228

Hi Shweta,

a second solution apart from what Venkat is sujjesting , which might help you in getting your goal.

As you have to show same material and different PO's values on each page.

You can create a Copies window as shown below, and write the same logic as i have sujjested

previously for segregating data in second page.

Please see the screenshot , and do as shown below in second page

For Copies window choose "Original and Copies- Copies Differ"

Write your logic same as in the first page and in the command of first page give the condition

LT_COUNT >= 3.

where lt_count is the no of rows for your PO's (in which you have unique PO's).

Now do it as shown here, and let me know(Please make a copy of your smartform that will be differ from as sujjested by Venkat, otherwise you will get confused).

Read only

0 Likes
8,228

Hi Sanjeev,

thanks a lot for your sujjestions, i am working on your sujjestions, but it seems too much coding will

be to perform inside my smartform.

One question please, can i use the same variable to show values on next page or i have to declare

another variables for that.

Read only

0 Likes
8,228

Hi Shweta,

yes you have to declare a separate variables for your second page data printing,

i know its complicated , because coding inside smartform is tough because of small window

size, but its a simple method if you don't wants complicated coding.

As you have done for your first page , just do it for second page too, and as i have sujjested

do the same thing.....

i hope you will get what you wants.

Read only

0 Likes
8,228

Hi Sanjeev,

i have worked as you have sujjested, and getting my result, but if possible can you elaborate

it at some extent , so that i can easily get my desired result,

If you have worked on the same scenario ever before, please mention it clearly once more.

Thanks in advance.

Read only

0 Likes
8,228

Hi Shweta,

please see what i have done, it will look handy, but a good solution.

First of all make 2 separate pages having a Main window in both, now perform your coding in first page

and make your second page empty.

i means to say that the contents of second page should be in first page itself, when the contents of first page gets ended, then create a command so that it will go on next page.

For first page in general attribute keep next page as PAGE2, and in the command after the commencement for first page keep it also to go to next page (page2).

Just see that all my contents are within my first  page, and i have to show its value in second page,

see in my second page mian window, its empty (i have taken all its contents in first page itself)

Read only

Former Member
0 Likes
8,228

This message was moderated.

Read only

Former Member
0 Likes
8,228

hello,

i am really sorry, as i said, i was getting failure notice when i tried to send you the answer, unfortunately all were sent accidently as i was keep clicking on reply button

i am really sorry

Read only

Former Member
0 Likes
8,228

hi,
please let me know if that was correct or helpful?
your problem got solved?

Read only

Former Member
0 Likes
8,228

Hi Shweta,

The requirement is pretty odd, you can try the following approach -

Have 3 internal tables -

it_mat_distinct - distinct set of materials

it_po - distinct set of POs

it_final - PO, Material, and Qty (master table)

Have another table IT_MAT for materials, which will have all the materials repeating (no of POs / 3 ) times. Logic would be -

describe table it_po lines v_lines.

v_lines = ceil( v_lines / 3 ).

do v_lines times.

  append lines of it_mat_distinct to it_mat.

enddo.

Get number of disctinc materials in v_mat_count.

describe table it_distinct lines v_mat_count.

In the smart form keep only one page, and one main window. Inside the main window, create one table that loops on IT_MAT . Keep an index that gets incremented in each loop pass.

The table should have 4 columns - one for material number, and 3 PO columns.

Create a code line in the second cell of Header row. Write the below logic -

Get the page number (sfsy-page) in v_page

Get v_index = (v_page - 1) * 3)

read IT_PO with index (v_index + 1) get the PO number in v_po.

Then create the text and Write the header text - "Qty for PO &V_PO&"

Do the same thing for third cell (second PO), but read index (v_index + 2) to get PO number.

Do the same thing for fourth cell (third PO), but read index (v_index + 3) to get PO number.

This should create the Headings on each page wth PO numbers.

Now, before printing the qty value for the i-th PO column (in Line item cell), write a code line with following logic -

Get the page number (ssfy-pagecount) in v_page.

Get v_index = (v_page - 1) * 3) + i.

read IT_PO with index v_index and get the PO number in v_po.

Read the it_final (master table) with the material (current loop pass) and PO number (v_po). Print the qty.

In the last cell, if the table index = v_mat_count, call the next page (which would be current page itself) using command.

I know its not very good in terms of a solution, but might serve your purpose. There is one assumption - the number of materials should not be that much, that it does not fit in one page.

Regards,

Read only

rosenberg_eitan
Active Contributor
0 Likes
8,228

Hi,

See if this is usfull in your case.

Regards.