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

Please send the ALV code

Former Member
0 Likes
2,257

Please send the ALV code.

requirement:

If the user having the role 1 I want to download all the fields

If the user having the role 2 I want to download the 2 or 3 fields.

Kindly send the code.

thanks in ad......

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,083

both r giving the same results:

i want like this;

-


1 2 3

1 2 3

-


if role = 2.

if i download alv report foor role 2. the result should be

-


1 2

1 2

-


22 REPLIES 22
Read only

Former Member
0 Likes
2,083

Here is the Pseudo Code

1. You need to have a custom button for download functionality

2. Upon clicking the button do a authority check

AUTHORITY-CHECK.

If sy-subrc = 0.

Download the entire internal table.

else.

Have another table with only those fields and copy the data from main internal table and then download.

endif.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

0 Likes
2,083

where i have to write the Auth check.

after the event_download is it correct.

its very helpfull answwer.

Read only

Former Member
0 Likes
2,083

Hi

U can try to use the authorizazions or check if the user belong or not belong to a certain role:

DATA: ROLE.

* Extract the fields for ALV
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            I_PROGRAM_NAME     = GT_REPID
            I_INTERNAL_TABNAME = 'T_OUTPUT'
            I_INCLNAME         = GT_REPID
*            I_STRUCTURE_NAME   = 'LFA1'
       CHANGING
            CT_FIELDCAT        = GT_FIELDCAT[].


* Check the authorizations:
  AUTHORITY-CHECK OBJECT <AUTH OBJECT>
           ID <ID> FIELD <FIELD>.
           
  IF SY-SUBRC = 0. 
    ROLE = '1'.
  ELSE.
    ROLE = '2'.
  ENDIF.


  LOOP AT GT_FIELDCAT INTO LS_FIELDCAT.  
    CASE LS_FIELDCAT-FIELDNAME.
      WHEN <FIELD1> OR <FIELD2> ....
         IF ROLE = '2'.
           DELETE GT_FIELDCAT.
         ENDIF.
      WHEN OTHERS.
      .............. 
    ENDCASE.
  ENDLOOP.

Max

Read only

0 Likes
2,083

MAX,

IN WHICH TABLE CAN I GET THE ROLES DETAILS AND USER DETAILS.

HOW I CAN LINK THESE DETAILS.

I AM DOING THE HRREPORT THE OUTPUT WILL DISPLAY IN ALV GRID.

PL GUIDE ME.

Read only

0 Likes
2,083

Hi

In table AGR_USERS you find all user roles.

My code should be good for you if "Download" means you don't have to show some fields.

Max

Read only

0 Likes
2,083

MAX,

CAN U SEND THE FULL CODINF PL

Read only

0 Likes
2,083

Here I use the fm for ALV, but the concept doesn't change for OO ALV.

I don't know how you use the ALV

TYPE-POOLS SLIS.

DATA: GT_FIELDCAT   TYPE SLIS_T_FIELDCAT_ALV,
      LS_FIELDCAT   TYPE SLIS_FIELDCAT_ALV,
      GT_REPID      LIKE SY-REPID.


DATA: T_ROLES LIKE STANDARD TABLE OF AGR_USERS WITH HEADER LINE.

DATA: BEGIN OF T_OUTPUT OCCURS 0,
        FIELD1,
        FIELD2,
        FIELD3,
        FIELD4,
        FIELDN,
      END   OF T_OUTPUT.

DATA: ROLE.


* Check user rules

SELECT * FROM AGR_USERS INTO TABLE T_ROLES WHERE UNAME = SY-UNAME
                                             AND FROM_DAT <= SY-DATUM
                                             AND TO_DAT => SY-DATUM.

READ TABLE T_ROLES WITH KEY AGR_NAME = '????????'.
IF SY-SUBRC = 0.
* User can see all fields.
  ROLE = '1'.
ELSE.
  ROLE = '2'.
ENDIF.




GT_REPID = SY-REPID.

* Extract the fields for ALV
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
          I_PROGRAM_NAME     = GT_REPID
          I_INTERNAL_TABNAME = 'T_OUTPUT'
          I_INCLNAME         = GT_REPID
     CHANGING
          CT_FIELDCAT        = GT_FIELDCAT[].


* Check the authorizations:

IF ROLE = '2'.
* Delete all fields the user can't see

  DELETE GT_FIELDCAT WHERE FIELDNAME = 'FIELD1'
                        OR FIELDNAME = 'FIELD2'.

ENDIF.

* Show the output

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
          I_CALLBACK_PROGRAM = GT_REPID
          IT_FIELDCAT        = GT_FIELDCAT
     TABLES
          T_OUTTAB           = T_OUTPUT.

Max

Read only

Former Member
0 Likes
2,083

MAX,

THANKS FOR UR HELP.

I AM GOING TO WRITE THE CODE.

CAN U GIVE UR YAHOO CHAT IT

Read only

Former Member
0 Likes
2,083

I HAVE WRITTEN THE BELOW CODE.

FIRST I TRY TO DISPLAY THE ALL RECORDS.

REPORT ZSSN

LINE-SIZE 140

LINE-COUNT 40

NO STANDARD PAGE HEADING.

----


  • Program Name : ZSSN Date Created : 11/13/2006 *

  • Author's Name : Satish (CN000244) *

  • Program Title : SSN Banking Info *

----


  • Tables

TABLES: PERNR,

T502T. " Marital Status Designators

TYPE-POOLS: SLIS.

  • Info Types

INFOTYPES: 0001,

0002.

  • Internal Tables

*DATA: T_P0002 LIKE STANDARD TABLE OF P0002 WITH HEADER LINE.

DATA: T_T502T LIKE STANDARD TABLE OF T502T WITH HEADER LINE.

DATA: STAT(10) TYPE C,

CHECK TYPE I.

DATA: BEGIN OF T_P0002 OCCURS 0,

BEGDA LIKE P0002-BEGDA,

ENDDA LIKE P0002-ENDDA,

NACHN LIKE P0002-NACHN,

VORNA LIKE P0002-VORNA,

FAMST LIKE T502T-FAMST,

FTEXT LIKE T502T-FTEXT,

END OF T_P0002.

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, "ALV Catalog Table

gs_fieldcat TYPE slis_fieldcat_alv. "ALV Catalog Structure

  • Start of selection

START-OF-SELECTION.

GET PERNR.

  • To get the marital status

SELECT * FROM T502T

INTO TABLE T_T502T

WHERE SPRSL = 'EN'.

IF SY-SUBRC EQ 0 .

SORT T_T502T BY FAMST .

ENDIF .

RP-READ-INFOTYPE P0002-PERNR 0002 P0002 PN-BEGDA PN-ENDDA.

RP-PROVIDE-FROM-LAST P0002 SPACE PN-BEGDA '31129999' .

IF PNP-SW-FOUND EQ '1' .

READ TABLE T_T502T WITH KEY FAMST = P0002-FAMST

BINARY SEARCH .

T_P0002-BEGDA = P0002-BEGDA.

T_P0002-ENDDA = P0002-ENDDA.

T_P0002-NACHN = P0002-NACHN.

T_P0002-VORNA = P0002-VORNA.

T_P0002-FAMST = P0002-FAMST.

T_P0002-FTEXT = T_T502T-FTEXT.

APPEND T_P0002.

endif.

gs_fieldcat-col_pos = '1'.

gs_fieldcat-fieldname = 'BEGDA'.

gs_fieldcat-outputlen = 10.

gs_fieldcat-seltext_l = 'BEGIN DATE'.

APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '2'.

gs_fieldcat-fieldname = 'ENDDA'.

gs_fieldcat-outputlen = 10.

gs_fieldcat-seltext_l = 'END DATE'.

APPEND gs_fieldcat TO gt_fieldcat.

CLEAR gs_fieldcat.

gs_fieldcat-col_pos = '3'.

gs_fieldcat-fieldname = 'NACHN'.

gs_fieldcat-outputlen = 15.

gs_fieldcat-seltext_l = 'LAST NAME'.

APPEND gs_fieldcat TO gt_fieldcat.

CLEAR gs_fieldcat.

gs_fieldcat-col_pos = '4'.

gs_fieldcat-fieldname = 'VORNA'.

gs_fieldcat-outputlen = 15.

gs_fieldcat-seltext_l = 'FIRST NAME'.

APPEND gs_fieldcat TO gt_fieldcat.

CLEAR gs_fieldcat.

gs_fieldcat-col_pos = '5'.

gs_fieldcat-fieldname = 'FAMST'.

gs_fieldcat-outputlen = 5.

gs_fieldcat-seltext_l = 'MARITAL KEY'.

APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '6'.

gs_fieldcat-fieldname = 'FTEXT'.

gs_fieldcat-outputlen = 5.

gs_fieldcat-seltext_l = 'MARITAL STATUS'.

APPEND gs_fieldcat TO gt_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_background_id = 'ALV_BACKGROUND'

i_grid_title = 'SSN BANK INFO'

  • i_structure_name = 'veda'

it_fieldcat = gt_fieldcat[]

TABLES

t_outtab = T_P0002.

Read only

0 Likes
2,083

Hi

In your situation:

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = GT_REPID

I_INTERNAL_TABNAME = 'T_P0002'

I_INCLNAME = GT_REPID

CHANGING

CT_FIELDCAT = GT_FIELDCAT[].

And the delete all fields the users can't see.

max_abap4@yahoo.it

Max

Read only

Former Member
0 Likes
2,083

kindly execute my program.

initially it displayed 1 record. when i click the back button it will add 1 more records ..like that it will increase the records.

Read only

0 Likes
2,083

Hi

Insert the call of grid in END-OF-SELECTION event:

START-OF-SELECTION.

GET PERNR.

  • To get the marital status

SELECT * FROM T502T

INTO TABLE T_T502T

WHERE SPRSL = 'EN'.

IF SY-SUBRC EQ 0 .

SORT T_T502T BY FAMST .

ENDIF .

RP-READ-INFOTYPE P0002-PERNR 0002 P0002 PN-BEGDA PN-ENDDA.

RP-PROVIDE-FROM-LAST P0002 SPACE PN-BEGDA '31129999' .

IF PNP-SW-FOUND EQ '1' .

READ TABLE T_T502T WITH KEY FAMST = P0002-FAMST

BINARY SEARCH .

T_P0002-BEGDA = P0002-BEGDA.

T_P0002-ENDDA = P0002-ENDDA.

T_P0002-NACHN = P0002-NACHN.

T_P0002-VORNA = P0002-VORNA.

T_P0002-FAMST = P0002-FAMST.

T_P0002-FTEXT = T_T502T-FTEXT.

APPEND T_P0002.

endif.

<b>END-OF-SELECTION</b>

gs_fieldcat-col_pos = '1'.

gs_fieldcat-fieldname = 'BEGDA'.

gs_fieldcat-outputlen = 10.

gs_fieldcat-seltext_l = 'BEGIN DATE'.

APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '2'.

gs_fieldcat-fieldname = 'ENDDA'.

gs_fieldcat-outputlen = 10.

gs_fieldcat-seltext_l = 'END DATE'.

APPEND gs_fieldcat TO gt_fieldcat.

CLEAR gs_fieldcat.

gs_fieldcat-col_pos = '3'.

gs_fieldcat-fieldname = 'NACHN'.

gs_fieldcat-outputlen = 15.

gs_fieldcat-seltext_l = 'LAST NAME'.

APPEND gs_fieldcat TO gt_fieldcat.

CLEAR gs_fieldcat.

gs_fieldcat-col_pos = '4'.

gs_fieldcat-fieldname = 'VORNA'.

gs_fieldcat-outputlen = 15.

gs_fieldcat-seltext_l = 'FIRST NAME'.

APPEND gs_fieldcat TO gt_fieldcat.

CLEAR gs_fieldcat.

gs_fieldcat-col_pos = '5'.

gs_fieldcat-fieldname = 'FAMST'.

gs_fieldcat-outputlen = 5.

gs_fieldcat-seltext_l = 'MARITAL KEY'.

APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '6'.

gs_fieldcat-fieldname = 'FTEXT'.

gs_fieldcat-outputlen = 5.

gs_fieldcat-seltext_l = 'MARITAL STATUS'.

APPEND gs_fieldcat TO gt_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_background_id = 'ALV_BACKGROUND'

i_grid_title = 'SSN BANK INFO'

  • i_structure_name = 'veda'

it_fieldcat = gt_fieldcat[]

TABLES

t_outtab = T_P0002.

Max

Read only

Former Member
0 Likes
2,083

MAX,

MY REQUIREMENT IS :

I WANT TO DISPLAY 7 FIELDS IN THE OUTPUT FOR BOTH ROLES.

WHEN THE ROLE 1 USER EXECUTE THE REPORT, IT IS NOT ALLOWED TO DOWNLOAD FOR 1 FILED.

WHEN THE ROLE 2 USER EXECUTE THE REPORT IT DOWNLOAD THE ALL FIELDS I.E 7 FIELDS.

I

Read only

0 Likes
2,083

Hi

Try this example:

TYPE-POOLS SLIS.

PARAMETERS: P_ROLE TYPE N.

DATA: GT_FIELDCAT   TYPE SLIS_T_FIELDCAT_ALV,
      ET_FIELDCAT   TYPE SLIS_T_FIELDCAT_ALV,
      LS_FIELDCAT   TYPE SLIS_FIELDCAT_ALV,
      GT_REPID      LIKE SY-REPID,
      GT_EVENT_EXIT TYPE SLIS_T_EVENT_EXIT,
      LT_EVENT_EXIT TYPE SLIS_EVENT_EXIT.


DATA: T_ROLES LIKE STANDARD TABLE OF AGR_USERS WITH HEADER LINE.

DATA: BEGIN OF T_OUTPUT OCCURS 0,
        FIELD1,
        FIELD2,
        FIELD3,
        FIELD4,
      END   OF T_OUTPUT.

DATA: ROLE.


* Check user rules

*SELECT * FROM AGR_USERS INTO TABLE T_ROLES WHERE UNAME = SY-UNAME
*                                             AND FROM_DAT <= SY-DATUM
*                                             AND TO_DAT => SY-DATUM.
*
*READ TABLE T_ROLES WITH KEY

DO 4 TIMES.
  MOVE SY-INDEX TO T_OUTPUT-FIELD1.
  T_OUTPUT-FIELD2 = T_OUTPUT-FIELD3 = T_OUTPUT-FIELD4 = T_OUTPUT-FIELD1.
  APPEND T_OUTPUT.
ENDDO.


GT_REPID = SY-REPID.

* Extract the fields for ALV
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
          I_PROGRAM_NAME     = GT_REPID
          I_INTERNAL_TABNAME = 'T_OUTPUT'
          I_INCLNAME         = GT_REPID
     CHANGING
          CT_FIELDCAT        = GT_FIELDCAT[].




LT_EVENT_EXIT-UCOMM  = '&XXL'.
LT_EVENT_EXIT-BEFORE = 'X'.
LT_EVENT_EXIT-AFTER  = 'X'.
APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.



* Check the authorizations:


ROLE = P_ROLE.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
          I_CALLBACK_PROGRAM      = GT_REPID
          I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
          IT_FIELDCAT             = GT_FIELDCAT
          IT_EVENT_EXIT           = GT_EVENT_EXIT
     TABLES
          T_OUTTAB                = T_OUTPUT.

*---------------------------------------------------------------------*
*       FORM user_command                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  R_UCOMM                                                       *
*  -->  RS_SELFIELD                                                   *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                        RS_SELFIELD TYPE SLIS_SELFIELD.

  CHECK R_UCOMM = '&XXL'. "Create (excel) file

  CHECK ROLE = '1'.

  IF RS_SELFIELD-BEFORE_ACTION = 'X'.
    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_GET'
         IMPORTING
              ET_FIELDCAT = ET_FIELDCAT.

* Save old chararcterstics
    GT_FIELDCAT[] = ET_FIELDCAT[].

    LOOP AT ET_FIELDCAT INTO LS_FIELDCAT WHERE FIELDNAME = 'FIELD2'
                                            OR FIELDNAME = 'FIELD3'
                                            OR FIELDNAME = 'FIELD4'.
      LS_FIELDCAT-NO_OUT = 'X'.
      MODIFY ET_FIELDCAT FROM LS_FIELDCAT.
    ENDLOOP.

* Set new layout
    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'
         EXPORTING
              IT_FIELDCAT = ET_FIELDCAT.

  ENDIF.




  IF RS_SELFIELD-AFTER_ACTION = 'X'.
* Set old layout
    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'
         EXPORTING
              IT_FIELDCAT = GT_FIELDCAT.
  ENDIF.
ENDFORM.

Max

Read only

Former Member
0 Likes
2,084

both r giving the same results:

i want like this;

-


1 2 3

1 2 3

-


if role = 2.

if i download alv report foor role 2. the result should be

-


1 2

1 2

-


Read only

0 Likes
2,083

Hi

How are you downloading the report?

I tried it and if the role is 1 only first colunm is dowloaded.

Max

Read only

0 Likes
2,083

In the selection screen i give 1 and execute the report.

it will display the 4 rows and 4 columns.

and then i try to download, using the local file and select it as spreadsheet

and save it as max.xls in local disk.

when i open the max.xls it will display all 4 columns and 4 rows.

thanks in ad

Read only

0 Likes
2,083

Hi

You haven't read well what I wrote.

In my previuos example I developed only the case to export the data to excel <u>(Spreadsheet option),</u> in this case the <b>OK_CODE is &XXL'</b>.

Now I've inserted all options to export the data:

OK_CODE -> &XXL --> Spreadsheet

OK_CODE -> &AQW --> Word Processing

OK_CODE -> %PC --> Local file

OK_CODE -> &CRTEMPL --> Crystal report

TYPE-POOLS SLIS.

PARAMETERS: P_ROLE TYPE N.

DATA: GT_FIELDCAT   TYPE SLIS_T_FIELDCAT_ALV,
      ET_FIELDCAT   TYPE SLIS_T_FIELDCAT_ALV,
      LS_FIELDCAT   TYPE SLIS_FIELDCAT_ALV,
      GT_REPID      LIKE SY-REPID,
      GT_EVENT_EXIT TYPE SLIS_T_EVENT_EXIT,
      LT_EVENT_EXIT TYPE SLIS_EVENT_EXIT.


DATA: T_ROLES LIKE STANDARD TABLE OF AGR_USERS WITH HEADER LINE.

DATA: BEGIN OF T_OUTPUT OCCURS 0,
        FIELD1,
        FIELD2,
        FIELD3,
        FIELD4,
      END   OF T_OUTPUT.

DATA: ROLE.


* Check user rules

*SELECT * FROM AGR_USERS INTO TABLE T_ROLES WHERE UNAME = SY-UNAME
*                                             AND FROM_DAT <= SY-DATUM
*                                             AND TO_DAT => SY-DATUM.
*
*READ TABLE T_ROLES WITH KEY

DO 4 TIMES.
  MOVE SY-INDEX TO T_OUTPUT-FIELD1.
  T_OUTPUT-FIELD2 = T_OUTPUT-FIELD3 = T_OUTPUT-FIELD4 = T_OUTPUT-FIELD1.
  APPEND T_OUTPUT.
ENDDO.


GT_REPID = SY-REPID.

* Extract the fields for ALV
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
          I_PROGRAM_NAME     = GT_REPID
          I_INTERNAL_TABNAME = 'T_OUTPUT'
          I_INCLNAME         = GT_REPID
     CHANGING
          CT_FIELDCAT        = GT_FIELDCAT[].



LT_EVENT_EXIT-BEFORE = 'X'.
LT_EVENT_EXIT-AFTER  = 'X'.
LT_EVENT_EXIT-UCOMM  = '&XXL'.  "<-- Excel
APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.
LT_EVENT_EXIT-UCOMM  = '&AQW'.  "<-- Word Processing
APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.
LT_EVENT_EXIT-UCOMM  = '%PC'.  "<-- Local file
APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.
LT_EVENT_EXIT-UCOMM  = '&CRTEMPL'. "<--- Crystal Report
APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.


* Check the authorizations:


ROLE = P_ROLE.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
          I_CALLBACK_PROGRAM      = GT_REPID
          I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
          IT_FIELDCAT             = GT_FIELDCAT
          IT_EVENT_EXIT           = GT_EVENT_EXIT
     TABLES
          T_OUTTAB                = T_OUTPUT.

*---------------------------------------------------------------------*
*       FORM user_command                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  R_UCOMM                                                       *
*  -->  RS_SELFIELD                                                   *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                        RS_SELFIELD TYPE SLIS_SELFIELD.

  CHECK ROLE = '2'.

  IF RS_SELFIELD-BEFORE_ACTION = 'X'.
    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_GET'
         IMPORTING
              ET_FIELDCAT = ET_FIELDCAT.

* Save old chararcterstics
    GT_FIELDCAT[] = ET_FIELDCAT[].

    LOOP AT ET_FIELDCAT INTO LS_FIELDCAT WHERE FIELDNAME = 'FIELD2'
                                            OR FIELDNAME = 'FIELD3'
                                            OR FIELDNAME = 'FIELD4'.
      LS_FIELDCAT-NO_OUT = 'X'.
      MODIFY ET_FIELDCAT FROM LS_FIELDCAT.
    ENDLOOP.

* Set new layout
    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'
         EXPORTING
              IT_FIELDCAT = ET_FIELDCAT.

  ENDIF.




  IF RS_SELFIELD-AFTER_ACTION = 'X'.
* Set old layout
    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'
         EXPORTING
              IT_FIELDCAT = GT_FIELDCAT.
  ENDIF.
ENDFORM.

Max

Read only

Former Member
0 Likes
2,083

thanks for ur unbelivable help.

thank uuuuuu soooooooooooooo much MAX.

Read only

0 Likes
2,083

Hi

I'm glad you have solved your problem and don't forget to close your other post with the same problem.

Max

Read only

Former Member
0 Likes
2,083

i am new to ALV.

as per ur program the role is 2 it's not showing o/p. can u pl look into this issue.

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "ALV Catalog Table

GS_FIELDCAT TYPE SLIS_FIELDCAT_ALV, "ALV Catalog Structure

GT_EVENT_EXIT TYPE SLIS_T_EVENT_EXIT,

LT_EVENT_EXIT TYPE SLIS_EVENT_EXIT,

ET_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

  • Internal Tables

DATA: T_T502T LIKE STANDARD TABLE OF T502T WITH HEADER LINE.

DATA: ROLE(1).

DATA: BEGIN OF T_FINAL OCCURS 0,

PERNR LIKE P0002-PERNR,

BEGDA LIKE P0002-BEGDA,

ENDDA LIKE P0002-ENDDA,

NACHN LIKE P0002-NACHN,

VORNA LIKE P0002-VORNA,

FAMST LIKE T502T-FAMST,

PERID LIKE P0002-PERID,

FTEXT LIKE T502T-FTEXT,

END OF T_FINAL.

DATA: BEGIN OF T_AGR_USERS OCCURS 0,

AGR_NAME LIKE AGR_USERS-AGR_NAME,

UNAME LIKE AGR_USERS-UNAME,

END OF T_AGR_USERS.

  • Start of selection

START-OF-SELECTION.

GET PERNR.

  • To get the marital status

SELECT * FROM T502T

INTO TABLE T_T502T

WHERE SPRSL = 'EN'.

IF SY-SUBRC EQ 0 .

SORT T_T502T BY FAMST .

ENDIF .

RP-READ-INFOTYPE P0002-PERNR 0002 P0002 PN-BEGDA PN-ENDDA.

RP-PROVIDE-FROM-LAST P0002 SPACE PN-BEGDA '31129999' .

IF PNP-SW-FOUND EQ '1' .

READ TABLE T_T502T WITH KEY FAMST = P0002-FAMST

BINARY SEARCH .

T_FINAL-PERNR = P0002-PERNR.

T_FINAL-BEGDA = P0002-BEGDA.

T_FINAL-ENDDA = P0002-ENDDA.

T_FINAL-NACHN = P0002-NACHN.

T_FINAL-VORNA = P0002-VORNA.

T_FINAL-FAMST = P0002-FAMST.

T_FINAL-PERID = P0002-PERID.

T_FINAL-FTEXT = T_T502T-FTEXT.

APPEND T_FINAL.

ENDIF.

SELECT AGR_NAME

UNAME FROM AGR_USERS

INTO TABLE T_AGR_USERS WHERE

UNAME = SY-UNAME.

READ TABLE T_AGR_USERS WITH KEY AGR_NAME = 'R1135'.

IF SY-SUBRC = 0.

ROLE = '1'.

ELSE.

ROLE = '2'.

ENDIF.

END-OF-SELECTION.

  • Extract the fields for ALV

GS_FIELDCAT-COL_POS = '1'.

GS_FIELDCAT-FIELDNAME = 'PERNR'.

GS_FIELDCAT-OUTPUTLEN = 15.

GS_FIELDCAT-SELTEXT_L = 'PERSONAL NUMBER'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

GS_FIELDCAT-COL_POS = '2'.

GS_FIELDCAT-FIELDNAME = 'BEGDA'.

GS_FIELDCAT-OUTPUTLEN = 10.

GS_FIELDCAT-SELTEXT_L = 'BEGIN DATE'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

GS_FIELDCAT-COL_POS = '3'.

GS_FIELDCAT-FIELDNAME = 'ENDDA'.

GS_FIELDCAT-OUTPUTLEN = 10.

GS_FIELDCAT-SELTEXT_L = 'END DATE'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

CLEAR GS_FIELDCAT.

GS_FIELDCAT-COL_POS = '4'.

GS_FIELDCAT-FIELDNAME = 'NACHN'.

GS_FIELDCAT-OUTPUTLEN = 15.

GS_FIELDCAT-SELTEXT_L = 'LAST NAME'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

CLEAR GS_FIELDCAT.

GS_FIELDCAT-COL_POS = '5'.

GS_FIELDCAT-FIELDNAME = 'VORNA'.

GS_FIELDCAT-OUTPUTLEN = 15.

GS_FIELDCAT-SELTEXT_L = 'FIRST NAME'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

CLEAR GS_FIELDCAT.

GS_FIELDCAT-COL_POS = '6'.

GS_FIELDCAT-FIELDNAME = 'FAMST'.

GS_FIELDCAT-OUTPUTLEN = 10 .

GS_FIELDCAT-SELTEXT_L = 'MARITAL KEY'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

GS_FIELDCAT-COL_POS = '7'.

GS_FIELDCAT-FIELDNAME = 'FTEXT'.

GS_FIELDCAT-OUTPUTLEN = 5.

GS_FIELDCAT-SELTEXT_L = 'MARITAL STATUS'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

GS_FIELDCAT-COL_POS = '8'.

GS_FIELDCAT-FIELDNAME = 'PERID'.

GS_FIELDCAT-OUTPUTLEN = 5.

GS_FIELDCAT-SELTEXT_L = 'SOCIAL SECURITY NUMBER'.

APPEND GS_FIELDCAT TO GT_FIELDCAT.

*IF ROLE = '1'.

*DELETE GT_FIELDCAT WHERE FIELDNAME = 'FAMST'.

*ENDIF.

LT_EVENT_EXIT-BEFORE = 'X'.

LT_EVENT_EXIT-AFTER = 'X'.

LT_EVENT_EXIT-UCOMM = '&XXL'. "<-- Excel

APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.

LT_EVENT_EXIT-UCOMM = '&AQW'. "<-- Word Processing

APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.

LT_EVENT_EXIT-UCOMM = '%PC'. "<-- Local file

APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.

LT_EVENT_EXIT-UCOMM = '&CRTEMPL'. "<--- Crystal Report

APPEND LT_EVENT_EXIT TO GT_EVENT_EXIT.

check ROLE = '2'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_GRID_TITLE = 'SSN BANK INFO'

IT_FIELDCAT = GT_FIELDCAT[]

TABLES

T_OUTTAB = T_FINAL.

----


  • FORM user_command *

----


  • ........ *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

CHECK ROLE = '1'.

IF RS_SELFIELD-BEFORE_ACTION = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_GET'

IMPORTING

ET_FIELDCAT = ET_FIELDCAT.

  • Save old chararcterstics

GT_FIELDCAT[] = ET_FIELDCAT[].

LOOP AT ET_FIELDCAT INTO LS_FIELDCAT WHERE FIELDNAME = 'FIELD2'

OR FIELDNAME = 'FIELD3'

OR FIELDNAME = 'FIELD4'.

LS_FIELDCAT-NO_OUT = 'X'.

MODIFY ET_FIELDCAT FROM LS_FIELDCAT.

ENDLOOP.

  • Set new layout

CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'

EXPORTING

IT_FIELDCAT = ET_FIELDCAT.

ENDIF.

IF RS_SELFIELD-AFTER_ACTION = 'X'.

  • Set old layout

CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'

EXPORTING

IT_FIELDCAT = GT_FIELDCAT.

ENDIF.

ENDFORM.

Read only

0 Likes
2,083

Hi

Delete this line:

*check ROLE = '2'. <----------------------------DELETE THIS

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
        I_GRID_TITLE = 'SSN BANK INFO'
        IT_FIELDCAT = GT_FIELDCAT[]
   TABLES
       T_OUTTAB = T_FINAL.

*---------------------------------------------------------------------*
* FORM user_command *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                                                  RS_SELFIELD TYPE SLIS_SELFIELD.

CHECK ROLE = '1'.

IF RS_SELFIELD-BEFORE_ACTION = 'X'.
  CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_GET'
      IMPORTING
         ET_FIELDCAT = ET_FIELDCAT.

* Save old chararcterstics
GT_FIELDCAT[] = ET_FIELDCAT[].

LOOP AT ET_FIELDCAT INTO LS_FIELDCAT 
" Here you have to replace the field FIELD1.... with your fields
                              WHERE FIELDNAME = 'FIELD2'
                                      OR FIELDNAME = 'FIELD3'
                                      OR FIELDNAME = 'FIELD4'.
  LS_FIELDCAT-NO_OUT = 'X'.
  MODIFY ET_FIELDCAT FROM LS_FIELDCAT.
ENDLOOP.

* Set new layout
CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'
  EXPORTING
       IT_FIELDCAT = ET_FIELDCAT.
ENDIF.

IF RS_SELFIELD-AFTER_ACTION = 'X'.
* Set old layout
  CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'
     EXPORTING
          IT_FIELDCAT = GT_FIELDCAT.
ENDIF.

ENDFORM.

Max

Message was edited by:

max bianchi