Tuesday, May 22, 2007

Grabar una variante de un Dynpro


Alguna vez han querido grabar una variante de un Dynpro? Aquí les dejo un pequeño ejemplo -:)

REPORT Z_VARIANTS.

*-----------------------------------------------------------------*
* TABLES *
*-----------------------------------------------------------------*
TABLES: SPFLI.

*-----------------------------------------------------------------*
* TYPE-POOLS *
*-----------------------------------------------------------------*
TYPE-POOLS: SLIS.

*-----------------------------------------------------------------*
* INTERNAL TABLES *
*-----------------------------------------------------------------*
DATA: T_RKEY TYPE STANDARD TABLE OF RSVARKEY WITH HEADER LINE,
T_SELCTAB TYPE STANDARD TABLE OF RSSCR WITH HEADER LINE,
T_VARI TYPE STANDARD TABLE OF RVARI WITH HEADER LINE,
IT_EXTAB TYPE SLIS_T_EXTAB,
WA_EXTAB LIKE LINE OF IT_EXTAB.

*-----------------------------------------------------------------*
* VARIABLES *
*-----------------------------------------------------------------*
DATA: OK_CODE TYPE SY-UCOMM,
W_VARIANT TYPE RSVAR-VARIANT,
W_USER_VARI TYPE RSVAR-VARIANT,
W_VARI_REPORT TYPE RSVAR-REPORT,
SEL_VARIANT TYPE RSVAR-VARIANT,
SEL_VARIANT_TEXT TYPE RSVAR-VTEXT,
W_REPORT TYPE RSVAR-REPORT,
VARIANT_EXISTS TYPE C.

*-----------------------------------------------------------------*
* SELECTION-SCREEN *
*-----------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
SELECT-OPTIONS: S_CARRID FOR SPFLI-CARRID,
S_CONNID FOR SPFLI-CONNID.
SELECTION-SCREEN END OF SCREEN 101.

*-----------------------------------------------------------------*
* INITIALIZATION *
*-----------------------------------------------------------------*
INITIALIZATION.

W_REPORT = SY-REPID.

PERFORM VARIANT_EXISTS.

*-----------------------------------------------------------------*
* START-OF-SELECTION *
*-----------------------------------------------------------------*
START-OF-SELECTION.

CALL SCREEN 0100.

*&----------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT *
*&----------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.

SET PF-STATUS '100' EXCLUDING IT_EXTAB.

ENDMODULE. " STATUS_0100 OUTPUT

*&----------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT *
*&----------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.

OK_CODE = SY-UCOMM.
CASE OK_CODE.
WHEN 'SAVE'.
PERFORM SAVE_VARIANT.
PERFORM VARIANT_EXISTS.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'GET_VAR'.
PERFORM LOAD_VARIANT.
WHEN 'DEL_VAR'.
PERFORM DELETE_VARIANT.
PERFORM VARIANT_EXISTS.
ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&----------------------------------------------------------------*
*& Form SAVE_VARIANT *
*&----------------------------------------------------------------*
FORM SAVE_VARIANT.

T_RKEY-REPORT = SY-REPID.
APPEND T_RKEY.

CALL FUNCTION 'RS_VARIANT_SAVE_FROM_SELSCREEN'
EXPORTING
CURR_REPORT = SY-REPID
VARI_REPORT = SY-REPID
IMPORTING
VARIANT = W_VARIANT
TABLES
P_SSCR = T_SELCTAB
P_VARI = T_VARI
EXCEPTIONS
ILLEGAL_VARIANT_NAME = 1
NOT_AUTHORIZED = 2
NO_REPORT = 3
REPORT_NOT_EXISTENT = 4
REPORT_NOT_SUPPLIED = 5
OTHERS = 6.

T_RKEY-VARIANT = W_VARIANT.
MODIFY T_RKEY INDEX 1.

CALL FUNCTION 'RS_RWSET_SAVE_VARIANT'
EXPORTING
RKEY = T_RKEY
TABLES
SELCTAB = T_SELCTAB.

ENDFORM. " SAVE_VARIANT

*&----------------------------------------------------------------*
*& Form LOAD_VARIANT *
*&----------------------------------------------------------------*
FORM LOAD_VARIANT.

PERFORM CHOOSE_VARIANT CHANGING SEL_VARIANT.

IF SEL_VARIANT NE SPACE.

CALL FUNCTION 'RS_SUPPORT_SELECTIONS'
EXPORTING
REPORT = W_REPORT
VARIANT = SEL_VARIANT
EXCEPTIONS
VARIANT_NOT_EXISTENT = 1
VARIANT_OBSOLETE = 2
OTHERS = 3.

ENDIF.

ENDFORM. " LOAD_VARIANT

*&----------------------------------------------------------------*
*& Form DELETE_VARIANT *
*&----------------------------------------------------------------*
FORM DELETE_VARIANT.

PERFORM CHOOSE_VARIANT CHANGING SEL_VARIANT.

IF SEL_VARIANT NE SPACE.

CALL FUNCTION 'RS_VARIANT_DELETE'
EXPORTING
REPORT = W_REPORT
VARIANT = SEL_VARIANT
FLAG_CONFIRMSCREEN = 'X'
FLAG_DELALLCLIENT = 'X'
EXCEPTIONS
NOT_AUTHORIZED = 1
NOT_EXECUTED = 2
NO_REPORT = 3
REPORT_NOT_EXISTENT = 4
REPORT_NOT_SUPPLIED = 5
VARIANT_LOCKED = 6
VARIANT_NOT_EXISTENT = 7
NO_CORR_INSERT = 8
VARIANT_PROTECTED = 9
OTHERS = 10.

ENDIF.

ENDFORM. " DELETE_VARIANT

*-----------------------------------------------------------------*
* FORM CHOOSE_VARIANT *
*-----------------------------------------------------------------*
FORM CHOOSE_VARIANT CHANGING L_SEL_VARIANT.

CALL FUNCTION 'RS_VARIANT_CATALOG'
EXPORTING
REPORT = W_REPORT
MASKED = 'X'
IMPORTING
SEL_VARIANT = L_SEL_VARIANT
SEL_VARIANT_TEXT = SEL_VARIANT_TEXT
EXCEPTIONS
NO_REPORT = 1
REPORT_NOT_EXISTENT = 2
REPORT_NOT_SUPPLIED = 3
NO_VARIANTS = 4
NO_VARIANT_SELECTED = 5
VARIANT_NOT_EXISTENT = 6
OTHERS = 7.

ENDFORM.

*&----------------------------------------------------------------*
*& Form VARIANT_EXISTS *
*&----------------------------------------------------------------*
FORM VARIANT_EXISTS.

CALL FUNCTION 'RS_VARIANT_FOR_ONE_SCREEN'
EXPORTING
PROGRAM = W_REPORT
DYNNR = '0101'
IMPORTING
VARIANT_EXISTS = VARIANT_EXISTS.

IF VARIANT_EXISTS EQ 'X'.
CLEAR: WA_EXTAB, IT_EXTAB.
REFRESH IT_EXTAB.
ELSE.
CLEAR: WA_EXTAB, IT_EXTAB.
REFRESH IT_EXTAB.
WA_EXTAB-FCODE = 'GET_VAR'.
APPEND WA_EXTAB TO IT_EXTAB.
ENDIF.

ENDFORM. " VARIANT_EXISTS


Y unas cuantas imagenes -;)






Saludos,

Blag.

3 comments:

katanka3 said...

Hola me da fallos, lo de grabar una variante.

katanka3 said...

Necesito ayuda, me da un fallo el codigo y no me graba las variantes

Alvaro "Blag" Tejada Galindo said...

Este código lo hice hace bastante tiempo...y en servidor que usé me funcionó perfectamente...se que en otras versiones el código da algunos errores...lee los comentarios en mi blog del SCN: http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6618

Saludos,
Blag.