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

Problem in module pool programming

Former Member
0 Likes
4,384

Hi all,

i have created a module pool program in which there is a screen field in which when ever user puts entry, then the subsequent record get shown in other screen field, at this level i have done it, but the problem is that user can edit those data and then he has to save those edited data.

I have written below codes , but the problem i am getting is that i am not able to get the edited data in my internal table, because it is still showing the previous data in my internal table. Please tell me what should i do next to get edited data in my internal table.

When user enters data in screen, i am getting data in my internal table as shown below

MODULE CHANGE_NOTICE INPUT.
   IF SY-UCOMM = 'ENTER'.
     IF P_NOTICE IS NOT INITIAL.
       SELECT * FROM ZLEGAL INTO TABLE IT_ZLEGAL WHERE NOTICE_ID = P_NOTICE.

         IF IT_ZLEGAL IS NOT INITIAL.
           READ TABLE IT_ZLEGAL INTO WA_ZLEGAL WITH KEY NOTICE_ID = P_NOTICE.
           IF SY-SUBRC = 0.
             WA_FINAL-MANDT = WA_ZLEGAL-MANDT.
             WA_FINAL-NOTICE_ID = WA_ZLEGAL-NOTICE_ID .
             WA_FINAL-CREATED WA_ZLEGAL-CREATED .
             WA_FINAL-CREATED_TIME = WA_ZLEGAL-CREATED_TIME .
             WA_FINAL-NOTICE_VER = WA_ZLEGAL-NOTICE_VER.
             WA_FINAL-NOTICE_DATE = WA_ZLEGAL-NOTICE_DATE .
             WA_FINAL-REC_DATE WA_ZLEGAL-REC_DATE .
             WA_FINAL-PROJECT WA_ZLEGAL-PROJECT .
             WA_FINAL-NOTICE_SOURCE WA_ZLEGAL-NOTICE_SOURCE .
             WA_FINAL-NOTICE_SUBJECT WA_ZLEGAL-NOTICE_SUBJECT .
             WA_FINAL-ADVOCATE WA_ZLEGAL-ADVOCATE .
             WA_FINAL-REF_DATE =   WA_ZLEGAL-REF_DATE .
             WA_FINAL-ADV_FEES WA_ZLEGAL-ADV_FEES .
             WA_FINAL-REC_AT WA_ZLEGAL-REC_AT.
             WA_FINAL-UNIT WA_ZLEGAL-UNIT.

             APPEND WA_FINAL TO IT_FINAL.
           ENDIF.
         ENDIF.
ENDIF.
ENDIF.
ENDMODULE.

and when user edits those data and on saving those data, i have written these code lines, but i have to get the edited data, and i am not getting how could a get the edited data (any of the above fields get edited , and only the notice_ver field will automatically get increased)

FORM SAVE_DOCUMENT .



SELECT MAX( NOTICE_VER ) INTO COUNT1 FROM ZLEGAL WHERE NOTICE_ID = P_NOTICE.
   COUNT1 = COUNT1 + 1.

   LOOP AT it_final INTO wa_final.
   WA_FINAL-MANDT = WA_FINAL-MANDT.
   WA_FINAL-NOTICE_ID = WA_FINAL-NOTICE_ID .
   WA_FINAL-CREATED WA_FINAL-CREATED .
   WA_FINAL-CREATED_TIME = WA_FINAL-CREATED_TIME .
   WA_FINAL-NOTICE_VER = count1.
   WA_FINAL-NOTICE_DATE = WA_FINAL-NOTICE_DATE .
   WA_FINAL-REC_DATE WA_FINAL-REC_DATE .
   WA_FINAL-PROJECT WA_FINAL-PROJECT .
   WA_FINAL-NOTICE_SOURCE WA_FINAL-NOTICE_SOURCE .
   WA_FINAL-NOTICE_SUBJECT WA_FINAL-NOTICE_SUBJECT .
   WA_FINAL-ADVOCATE WA_FINAL-ADVOCATE .
   WA_FINAL-REF_DATE =   WA_FINAL-REF_DATE .
   WA_FINAL-ADV_FEES WA_FINAL-ADV_FEES .
   WA_FINAL-REC_AT WA_FINAL-REC_AT.
   WA_FINAL-UNIT WA_FINAL-UNIT.

   MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING MANDT NOTICE_ID CREATED CREATED_TIME
   NOTICE_VER NOTICE_DATE REC_DATE PROJECT NOTICE_SOURCE NOTICE_SUBJECT ADVOCATE
   ADV_FEES REC_AT UNIT.

*APPEND wa_final1 to it_final1.
ENDLOOP.
ENDFORM.


Please tell me the process in between these two steps so that i will get my edited data in it_final, so that i can use it for save.

26 REPLIES 26
Read only

Former Member
0 Likes
4,338

Hi Srikant,

How your showing this IT_FINAL information in screen, it is in tabular format? Can you share sample screen shot.

Thanks,

Ashok.

Read only

0 Likes
4,338

Hi Ashok,

no its not through tables, these are independent variables in screen. It is something like this screenshot

Read only

0 Likes
4,338

Hi,

Instead of LOOP... ENDLOOP you can use only modify statement. Because already  WA_FINAL having modified data except below line


WA_FINAL-NOTICE_VER = count1.


And also while modifying internal table you need to mention either WHERE condition or  INDEX at where condition.


Before going modify use read statement based on key field information



  READ TABLE IT_FINALINTO WA_FINAL WITH KEY NOTICE_ID = P_NOTICE.


IF SY-SUBRC EQ O.
   WA_FINAL-NOTICE_ID = WA_FINAL-NOTICE_ID .
   WA_FINAL-CREATED WA_FINAL-CREATED .
   WA_FINAL-CREATED_TIME = WA_FINAL-CREATED_TIME .
   WA_FINAL-NOTICE_VER = count1.
   WA_FINAL-NOTICE_DATE = WA_FINAL-NOTICE_DATE .
   WA_FINAL-REC_DATE WA_FINAL-REC_DATE .
   WA_FINAL-PROJECT WA_FINAL-PROJECT .
   WA_FINAL-NOTICE_SOURCE WA_FINAL-NOTICE_SOURCE .
   WA_FINAL-NOTICE_SUBJECT WA_FINAL-NOTICE_SUBJECT .
   WA_FINAL-ADVOCATE WA_FINAL-ADVOCATE .
   WA_FINAL-REF_DATE =   WA_FINAL-REF_DATE .
   WA_FINAL-ADV_FEES WA_FINAL-ADV_FEES .
   WA_FINAL-REC_AT WA_FINAL-REC_AT.
   WA_FINAL-UNIT WA_FINAL-UNIT.

   MODIFY IT_FINAL FROM WA_FINAL INDEX SY-TABIX TRANSPORTING NOTICE_ID CREATED CREATED_TIME
   NOTICE_VER  NOTICE_DATE REC_DATE PROJECT NOTICE_SOURCE NOTICE_SUBJECT ADVOCATE    ADV_FEES REC_AT UNIT.

endif.



Thanks,

Ashok.

Read only

0 Likes
4,338

Hi Ashok kuma,

please tell me one thing that without looping on final table how could you modify it.

I am not getting it.

Read only

arthur_alvesteixeira
Active Participant
0 Likes
4,338

Srikant,

in PAI module loop at your table control and update your internal table.

Read only

0 Likes
4,338

Hi,

its not a table control, these are independent screen elements as shown in above screen shot.

Read only

0 Likes
4,338

So it's a global variable.... if yes, move it to internal table

Read only

rajkumarnarasimman
Active Contributor
0 Likes
4,338

Hi Srikant,

In Flow logic, please confirm the subroutine 'CHANGE_NOTICE INPUT' is called after all the Field statement is executed.

Please find the below screenshot. Here GET_VALUE subroutine is called after all the Field is defined.  If the same is done, you will get the changed values in Work Area  instead of old values.

Flow Logic - CHAIN.... ENDCHAIN Statement

Regards

Rajkumar Narasimman

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
4,338

Hello Srikanth,

Use 'ON REQUEST' module pool event to know the changed value in a i/o filed.


FIELD <filedname> MODULE check_change ON REQUEST.


Please go through the HELP from SAP.


Conditional Module Calls (SAP Library - SAP NetWeaver by Key Capability)

Read only

Former Member
0 Likes
4,338

Hi Srikant,

please look at the below simple example you have an idea how to get your new value.

for example in my screen i have just 2 fields say qmel-qmart & qmel-qmtxt. if i click on button 'GO' then based on qmel-qmart = 'Q2' i am filling qmel-qmtxt = TEST1. then user is changing value from TEST1 to TEST2. now with this below code i will get TEST2 only, not TEST1.

  PROCESS BEFORE OUTPUT.

PROCESS AFTER INPUT.

  MODULE user_command_1001.

   MODULE user_command_1001 INPUT.

  TABLES: qmel.

  IF sy-ucomm = 'GO'.

    IF qmel-qmart = 'Q2' AND
       qmel-qmtxt IS INITIAL.
      qmel-qmtxt = 'TEST1'.
    ENDIF.
  ELSEIF sy-ucomm = 'CANCEL'.
    LEAVE TO SCREEN 0.
  ENDIF.

  CLEAR sy-ucomm.

ENDMODULE.                 " USER_COMMAND_1001  INPUT

please analyse this simple example, then you can do for yours.

please let me if its not clear.

Regards,

Prasad

Read only

0 Likes
4,338

Hi Srikanth,

I think may be your using single record of zlegal on screen at a time in that case just check the modificetion below..

MODULE CHANGE_NOTICE INPUT.
   IF SY-UCOMM = 'ENTER'.
     IF P_NOTICE IS NOT INITIAL.
       SELECT * FROM ZLEGAL INTO TABLE IT_ZLEGAL WHERE NOTICE_ID = P_NOTICE.

         IF IT_ZLEGAL IS NOT INITIAL.
           READ TABLE IT_ZLEGAL INTO WA_ZLEGAL WITH KEY NOTICE_ID = P_NOTICE.
           IF SY-SUBRC = 0.
             WA_FINAL-MANDT = WA_ZLEGAL-MANDT.
             WA_FINAL-NOTICE_ID = WA_ZLEGAL-NOTICE_ID .
             WA_FINAL-CREATED WA_ZLEGAL-CREATED .
             WA_FINAL-CREATED_TIME = WA_ZLEGAL-CREATED_TIME .
             WA_FINAL-NOTICE_VER = WA_ZLEGAL-NOTICE_VER.
             WA_FINAL-NOTICE_DATE = WA_ZLEGAL-NOTICE_DATE .
             WA_FINAL-REC_DATE WA_ZLEGAL-REC_DATE .
             WA_FINAL-PROJECT WA_ZLEGAL-PROJECT .
             WA_FINAL-NOTICE_SOURCE WA_ZLEGAL-NOTICE_SOURCE .
             WA_FINAL-NOTICE_SUBJECT WA_ZLEGAL-NOTICE_SUBJECT .
             WA_FINAL-ADVOCATE WA_ZLEGAL-ADVOCATE .
             WA_FINAL-REF_DATE =   WA_ZLEGAL-REF_DATE .
             WA_FINAL-ADV_FEES WA_ZLEGAL-ADV_FEES .
             WA_FINAL-REC_AT WA_ZLEGAL-REC_AT.
             WA_FINAL-UNIT WA_ZLEGAL-UNIT.

             APPEND WA_FINAL TO IT_FINAL.

           

             GV_INDEX = SY-TABIX.


           ENDIF.
         ENDIF.
ENDIF.
ENDIF.
ENDMODULE.

And use this index to modify it_final.


FORM SAVE_DOCUMENT .

SELECT MAX( NOTICE_VER ) INTO COUNT1 FROM ZLEGAL WHERE NOTICE_ID = P_NOTICE.
   COUNT1 = COUNT1 + 1.

  * LOOP AT it_final INTO wa_final.
  * WA_FINAL-MANDT = WA_FINAL-MANDT.
  * WA_FINAL-NOTICE_ID = WA_FINAL-NOTICE_ID .
  * WA_FINAL-CREATED WA_FINAL-CREATED .
  * WA_FINAL-CREATED_TIME = WA_FINAL-CREATED_TIME .
   WA_FINAL-NOTICE_VER = count1.
  * WA_FINAL-NOTICE_DATE = WA_FINAL-NOTICE_DATE .
  * WA_FINAL-REC_DATE WA_FINAL-REC_DATE .
  * WA_FINAL-PROJECT WA_FINAL-PROJECT .
  * WA_FINAL-NOTICE_SOURCE WA_FINAL-NOTICE_SOURCE .
  * WA_FINAL-NOTICE_SUBJECT WA_FINAL-NOTICE_SUBJECT .
  * WA_FINAL-ADVOCATE WA_FINAL-ADVOCATE .
  * WA_FINAL-REF_DATE =   WA_FINAL-REF_DATE .
  * WA_FINAL-ADV_FEES WA_FINAL-ADV_FEES .
   *WA_FINAL-REC_AT WA_FINAL-REC_AT.
  * WA_FINAL-UNIT WA_FINAL-UNIT.

   MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING MANDT NOTICE_ID CREATED CREATED_TIME
   NOTICE_VER NOTICE_DATE REC_DATE PROJECT NOTICE_SOURCE NOTICE_SUBJECT ADVOCATE
   ADV_FEES REC_AT UNIT INDEX GV_INDEX.

*APPEND wa_final1 to it_final1.
ENDLOOP.
ENDFORM.

Actually you Are looping it_final and taking that old values again into wa_final and assign same values back to it_final

Do these changes you will get the Changes captured in it_final..

Regards,

Shashikanth

Read only

Former Member
0 Likes
4,338

Any other suggestion, i am not getting my edited data still in my internal table.

Please suggest me how could i achieve it.

Read only

0 Likes
4,338

Hi srikanth,

You commented the loop and checked the internal table.see the code and remove that loop ypu will get the edited data in internal table

Regards,

shashikanth


Read only

0 Likes
4,338

Hi Srikant,

I have few questions -

1. What are input fields ? Changed values will be there in these input fields not wa_final as i can see you updating same thing inside loop except notice_ver.

1. Where you updating ZLEGAL table ?

2. Are you expecting changed value also needs to displayed on second screen at time of save ?

3. After saving the records, once you enter the these new values are reflecting in second screen ?

Use field symbols

LOOP AT it_final ASSIGNING <wa_final>..

    <WA_FINAL>-NOTICE_VER = count1.

ENDLOOP.

Thanks & Regards,

Arun

Read only

0 Likes
4,338

Hi Aruna,

thanks a lot for your support.

the input fields are the same in which i am getting my data, for your references....There is a screen program similar to this where user enters all data and after entering it it will be saved, while saving in zlegal table it will generate a serial no, and this is the value of  P_NOTICE.

Now, when user put these P_NOTICE value in this screen, i am calling all the data that was previously saved for this P_NOTICE, now when all the data get displayed, user can change any of these data, and a have to save the changed data with each time increasing NOTICE_VER.


Now the problem is that when i am getting data in all the fields which are in my work area like WA_FINAL-NOTICE_SOURCE, the all fields are in my work area that i am showing on screen. so i wants to change these data (edit) on screen , and the edited data should be again get saved in my internal table.

But the problem i am facing is that i am not able to get the edited data, please see this whole scenario then tell me the solution.

Read only

0 Likes
4,338

Hi Srikant,

I'm assuming you used WA_FINAL structure fields as input fields. e.g wa_final-notice_souce as input for screen field  'Notice Source ' .

Actual issue is in LOOP AT it_final INTO wa_final.

WA_FINA structure which has changed value (screen value) getting over written with IT_FINAL when you looped into wa_final.

Change the code like -

LOOP AT it_final ASSIGNING <fs_final>.

   <fs_FINAL>-NOTICE_ID = WA_FINAL-NOTICE_ID .

  

  < fs_FINAL>-NOTICE_SOURCE WA_FINAL-NOTICE_SOURCE .

   <fs_FINAL>-NOTICE_SUBJECT WA_FINAL-NOTICE_SUBJECT .

   <fs_FINAL>-NOTICE_VER = count1.

   .....

* Required fields

ENDLOOP.


For better coding use different structure or field names to represent the screen fields


Thanks & Regards,

Arun


Read only

0 Likes
4,338

Hi Aruna,

please tell me one thing, how could it will change my screen fields, and what do you mean by creating different structure, actually firstly i have to display all the data based on that NOTICE_ID, so i have created such type of structures which is similar to my z table.

Read only

0 Likes
4,338

Hi Srikant,

Using same structure both as screen fields and work area will complicate the program as you facing . What i meant was create different field or at least different work area like create P_NOTICE_SOURCE for Notice source etc.

I can see lot of optimization required in your code.

Like ,  if WA_ZLEGAL and WA_FINAL both are structure type , then you directly use WA_FINAL instead moving to WA_ZLNEGAL  than coping into WA_FINAL

Thanks & Regards,

Arun



Read only

0 Likes
4,338

Hi Aruna,

please clear one thing while calling my data based on notice_id if i will put the screen name as p_notice_id, what will be different. When all the fields will be of the same declaration, when user will edit data it will have again his data in these fields.

Tell me how could he will change and then it will reflect in my program.

Read only

0 Likes
4,338

Assumed P_NOTICE_SOURCE is defined for notice source.

MODULE CHANGE_NOTICE INPUT.

   IF SY-UCOMM = 'ENTER'.

     IF P_NOTICE IS NOT INITIAL.

       SELECT * FROM ZLEGAL INTO TABLE IT_ZLEGAL WHERE NOTICE_ID = P_NOTICE.

         IF IT_ZLEGAL IS NOT INITIAL.

           READ TABLE IT_ZLEGAL INTO WA_FINAL WITH KEY NOTICE_ID = P_NOTICE.

           IF SY-SUBRC = 0.


             P_NOTICE_SOURCE =  WA_FINAL-NOTICE_SOURCE.

* Like that other fields

             APPEND WA_FINAL TO IT_FINAL.

           ENDIF.

         ENDIF.

ENDIF.

ENDIF.

ENDMODULE.



FORM SAVE_DOCUMENT .


field symbol : <fs_final> like line of it_final.

  SELECT MAX( NOTICE_VER ) INTO COUNT1 FROM ZLEGAL WHERE NOTICE_ID = P_NOTICE.

   COUNT1 = COUNT1 + 1.


  LOOP AT it_final ASSIGNING to <FS_FINAL>.


  <FS_FINAL>-NOTICE_VER = count1.

<FS_FINAL>-NOTICE_SOURCE = P_NOTICE_SOURCE.


ENDLOOP.


ENDFORM.



In PAI MODULE - Use Field Statment

LIke

FIELD  P_NOTICE_SOURCE



Read only

bharat_rathod2
Active Participant
0 Likes
4,338

Dear,

use chain ,endchain and module to get updated data into internal table.

Read only

srikanth_d4
Participant
0 Likes
4,338

Hi Srikanth,

Before SAVE use this FM: DYNP_VALUES_UPDATE & DYNP_VALUES_READ

It may help

Regards,

Srikanth

Read only

VenkatRamesh_V
Active Contributor
0 Likes
4,338

Hi Srikanth Jain,

Before Saving,

Pass the Internal table content to another Internal table( Temp).

After Saving Compare both Internal tables.

Regards,

Venkat.

Read only

Former Member
0 Likes
4,338

Hi,

In PAI, use the FIELD statement to transfer the screen values to the variables. After the FIELD, call your module. The edited values will be available.

Regards

Nida

Read only

kabil_g
Active Participant
0 Likes
4,338

Hi Srikant,,


Remove your looping...............


DATA: it_tab TYPE TABLE OF ty_tab,

             wa_zcalc TYPE ty_tab,

             it_final TYPE TABLE OFmara,

             wa_calc TYPE mara,


MOVE-CORRESPONDING  wa_st TO wa_Final.

      MODIFY IT_FINAL FROM WA_FINAL INDEX SY-TABIX TRANSPORTING mandt

Read only

Former Member
0 Likes
4,338

Hi Srikant Jain,

if p_notice  is not initial  you need change to if IT_ZLEGAL is inital.


if u edit the first screen and then while you enter that time system again fetch from the table based on that system fill the itab. so if you change IT_ZLEGAL is inital  then first time only system fetch the record after that it wont change fetch the value.

MODULE CHANGE_NOTICE INPUT.
   IF SY-UCOMM = 'ENTER'.
    IF P_NOTICE IS NOT INITIAL.
       SELECT * FROM ZLEGAL INTO TABLE IT_ZLEGAL WHERE NOTICE_ID = P_NOTICE.