ALV中动态内表+行转化为列–老白

ALV中动态内表+行转化为列–老白

071101103234.jpg

转换为:
071101104029.jpg
REPORT z_barry_test_fieldsymols .
TYPE-POOLS: slis.

TABLES: mseg,mkpf.
DATA: gd_fieldcat TYPE slis_t_fieldcat_alv.

DATA: sla TYPE slis_layout_alv ,

      ivariant LIKE disvariant,

      i_repid LIKE sy-repid ,

      i_excluding TYPE slis_t_extab.
TYPES: BEGIN OF ty_sum ,

        werks LIKE mseg-werks ,

        matnr LIKE mseg-matnr ,

        lgort LIKE mseg-lgort ,

        bwart LIKE mseg-bwart ,

        menge LIKE mseg-menge ,

      END OF ty_sum.

DATA : itab TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .

DATA : hs_sum TYPE HASHED TABLE OF ty_sum

       WITH UNIQUE KEY werks matnr lgort bwart WITH HEADER LINE .

DATA : itab_sum TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .
DATA: BEGIN OF itab_out OCCURS 0,

        werks LIKE mseg-werks ,

        matnr LIKE mseg-matnr ,

        lgort LIKE mseg-lgort ,

        menge01 TYPE i        ,

        menge02 TYPE i        ,

        menge03 TYPE i        ,

        menge04 TYPE i        ,

        menge05 TYPE i        ,

        menge06 TYPE i        ,

        menge07 TYPE i        ,

        menge08 TYPE i        ,

        menge09 TYPE i        ,

        menge10 TYPE i        ,

        menge11 TYPE i        ,

        menge12 TYPE i        ,

        menge13 TYPE i        ,

        menge14 TYPE i        ,

        menge15 TYPE i        ,

        menge16 TYPE i        ,

        menge17 TYPE i        ,

        menge18 TYPE i        ,

        menge19 TYPE i        ,

        menge20 TYPE i        ,

        menge21 TYPE i        ,

        menge22 TYPE i        ,

        menge23 TYPE i        ,

        menge24 TYPE i        ,

        menge25 TYPE i        ,

        menge26 TYPE i        ,

        line_sum TYPE i       ,

      END OF itab_out.
TYPES: BEGIN OF ty_bwart ,

        bwart LIKE mseg-bwart ,

      END OF ty_bwart.

DATA : hs_bwart TYPE HASHED TABLE OF ty_bwart

       WITH UNIQUE KEY bwart WITH HEADER LINE .

DATA : itab_bwart TYPE STANDARD TABLE OF ty_bwart WITH HEADER LINE .
FIELD-SYMBOLS: <f_fs1> ,

               <f_fs2>.

DATA: max_count TYPE i .
SELECT-OPTIONS: s_mblnr FOR mseg-mblnr ,

                s_budat FOR mkpf-budat .

PARAMETERS:     p_sum AS CHECKBOX .
START-OF-SELECTION.

PERFORM getdata.

PERFORM fixdata.

IF p_sum = ‘X’.

    PERFORM outdata.

ELSE.

    PERFORM outdata2.

ENDIF.
*&———————————————————————*

*&      Form GETDATA

*&———————————————————————*

FORM getdata.

SELECT werks matnr lgort bwart menge INTO TABLE itab

FROM mkpf INNER JOIN mseg ON mkpf~mblnr = mseg~mblnr AND

                               mkpf~mjahr = mseg~mjahr

WHERE mkpf~mblnr IN s_mblnr AND

        mkpf~budat IN s_budat .

ENDFORM.                    ” GETDATA
*&———————————————————————*

*&      Form FIXDATA

*&———————————————————————*

FORM fixdata.

DATA: index LIKE sy-tabix .
LOOP AT itab.

    hs_sum = itab.

    COLLECT hs_sum.
    hs_bwart = itab-bwart .

    COLLECT hs_bwart.

ENDLOOP.
SORT hs_bwart.

itab_bwart[] = hs_bwart[].

itab_sum[] = hs_sum[].
LOOP AT itab_sum.

    itab_out-werks = itab_sum-werks .

    itab_out-matnr = itab_sum-matnr .

    itab_out-lgort = itab_sum-lgort .

    READ TABLE itab_bwart WITH KEY bwart = itab_sum-bwart .

    index = sy-tabix + 3.

    ASSIGN COMPONENT index OF STRUCTURE itab_out TO <f_fs1>.

    <f_fs1> = itab_sum-menge.

    itab_out-line_sum = itab_sum-menge.

    COLLECT itab_out.

    CLEAR itab_out.

ENDLOOP.

ENDFORM.                    ” FIXDATA
*&———————————————————————*

*&      Form outdata

*&———————————————————————*

FORM outdata.

PERFORM fieldcat_init .

sla-colwidth_optimize = ‘X’.

sla-zebra             = ‘X’.

i_repid = sy-repid.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

       EXPORTING

            i_callback_program      = i_repid

            it_fieldcat             = gd_fieldcat[]

            i_save                  = ‘A’

            is_variant              = ivariant

            is_layout               = sla

            it_excluding            = i_excluding

            i_callback_user_command = ‘USER_COMMAND’

       TABLES

            t_outtab                = itab_sum

       EXCEPTIONS

            program_error           = 1

            OTHERS                  = 2.
ENDFORM.                    ” outdata

*———————————————————————*

*       FORM fieldcat_init                                            *

*———————————————————————*

FORM fieldcat_init .

PERFORM frm_catlg_set USING: ‘WERKS’     ‘WERKS’ ‘X’ ,

                               ‘MATNR’     ‘MATNR’ ‘X’ ,

                               ‘LGORT’     ‘LGORT’ ‘X’ ,

                               ‘BWART’     ‘BWART’ ‘X’ ,

                               ‘MENGE’     ‘MENGE’ ” .

ENDFORM.                    “fieldcat_init
*———————————————————————*

*       FORM frm_catlg_set                                            *

*———————————————————————*

FORM frm_catlg_set USING p_field

                         p_text

                         p_key.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat-fieldname     = p_field.

ls_fieldcat-seltext_l     = p_text.

ls_fieldcat-key           = p_key.
IF p_field = ‘LINE_SUM’.

    ls_fieldcat-emphasize = ‘C700’.

ENDIF.

APPEND ls_fieldcat TO gd_fieldcat .

CLEAR ls_fieldcat .

ENDFORM.                    “frm_catlg_set
*&——————————————————————–*

*&      Form user_command

*&——————————————————————–*

FORM user_command USING r_ucomm LIKE sy-ucomm

                    rs_selfield TYPE slis_selfield.

READ TABLE itab INDEX rs_selfield-tabindex.

CASE r_ucomm.

    WHEN ‘&IC1’. “双击
    WHEN ‘EXIT’.

      LEAVE PROGRAM.

ENDCASE.

rs_selfield-refresh = ‘X’. “自动刷新

ENDFORM. “user_com
*———————————————————————*

*       FORM outdata2                                                 *

*———————————————————————*

FORM outdata2.

PERFORM fieldcat_init2 .
sla-colwidth_optimize = ‘X’.

sla-zebra             = ‘X’.

i_repid = sy-repid.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

       EXPORTING

            i_callback_program      = i_repid

            it_fieldcat             = gd_fieldcat[]

            i_save                  = ‘A’

            is_variant              = ivariant

            is_layout               = sla

            it_excluding            = i_excluding

            i_callback_user_command = ‘USER_COMMAND’

       TABLES

            t_outtab                = itab_out

       EXCEPTIONS

            program_error           = 1

            OTHERS                  = 2.

ENDFORM.                    ” outdata
*———————————————————————*

*       FORM fieldcat_init2                                           *

*———————————————————————*

FORM fieldcat_init2 .

DATA: c(2) TYPE n ,

        txt(20) TYPE c .
PERFORM frm_catlg_set USING: ‘WERKS’   ‘WERKS’ ‘X’ ,

                               ‘MATNR’   ‘MATNR’ ‘X’ ,

                               ‘LGORT’   ‘LGORT’ ‘X’ .

LOOP AT hs_bwart .

    c = c + 1.

    CONCATENATE ‘MENGE’ c INTO txt.

    PERFORM frm_catlg_set USING: txt hs_bwart-bwart ” .

ENDLOOP.

PERFORM frm_catlg_set USING: ‘LINE_SUM’ ‘SUM’ ” .

ENDFORM.                    “fieldcat_init
使用指针动态生成内表的方法:
REPORT z_barry_test_fieldsymols .
TYPE-POOLS: slis.

TABLES: mseg,mkpf.
DATA: gd_fieldcat TYPE slis_t_fieldcat_alv.

DATA: sla TYPE slis_layout_alv ,

      ivariant LIKE disvariant,

      i_repid LIKE sy-repid ,

      i_excluding TYPE slis_t_extab.
TYPES: BEGIN OF ty_sum ,

        werks LIKE mseg-werks ,

        matnr LIKE mseg-matnr ,

        lgort LIKE mseg-lgort ,

        bwart LIKE mseg-bwart ,

        menge LIKE mseg-menge ,

      END OF ty_sum.

DATA : itab TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .

DATA : hs_sum TYPE HASHED TABLE OF ty_sum

       WITH UNIQUE KEY werks matnr lgort bwart WITH HEADER LINE .

DATA : itab_sum TYPE STANDARD TABLE OF ty_sum WITH HEADER LINE .
TYPES: BEGIN OF ty_bwart ,

        bwart LIKE mseg-bwart ,

      END OF ty_bwart.

DATA : hs_bwart TYPE HASHED TABLE OF ty_bwart

       WITH UNIQUE KEY bwart WITH HEADER LINE .

DATA : itab_bwart TYPE STANDARD TABLE OF ty_bwart WITH HEADER LINE .
FIELD-SYMBOLS: <f_fs1> ,

               <f_out> TYPE STANDARD TABLE ,

               <f_out_wa> .

DATA: max_count TYPE i ,

      dy_out    TYPE REF TO data ,

      dy_out_wa TYPE REF TO data,

      xfc       TYPE lvc_s_fcat,

      ifc       TYPE lvc_t_fcat.

DATA: c(2) TYPE n ,

      txt(20) TYPE c .

SELECT-OPTIONS: s_mblnr FOR mseg-mblnr ,

                s_budat FOR mkpf-budat .

PARAMETERS:     p_sum AS CHECKBOX .
START-OF-SELECTION.

PERFORM getdata.

PERFORM fixdata.

IF p_sum = ‘X’.

    PERFORM outdata.

ELSE.

    PERFORM outdata2.

ENDIF.
*&———————————————————————*

*&      Form GETDATA

*&———————————————————————*

FORM getdata.

SELECT werks matnr lgort bwart menge INTO TABLE itab

FROM mkpf INNER JOIN mseg ON mkpf~mblnr = mseg~mblnr AND

                               mkpf~mjahr = mseg~mjahr

WHERE mkpf~mblnr IN s_mblnr AND

        mkpf~budat IN s_budat .

ENDFORM.                    ” GETDATA
*&———————————————————————*

*&      Form FIXDATA

*&———————————————————————*

FORM fixdata.

DATA: index LIKE sy-tabix .
LOOP AT itab.

    hs_sum = itab.

    COLLECT hs_sum.
    hs_bwart = itab-bwart .

    COLLECT hs_bwart.

ENDLOOP.
SORT hs_bwart.

itab_bwart[] = hs_bwart[].

itab_sum[] = hs_sum[].
PERFORM creat_itab_out.
LOOP AT itab_sum.

    ASSIGN COMPONENT ‘WERKS’ OF STRUCTURE <f_out_wa> TO <f_fs1>.

    <f_fs1> = itab_sum-werks.

    ASSIGN COMPONENT ‘MATNR’ OF STRUCTURE <f_out_wa> TO <f_fs1>.

    <f_fs1> = itab_sum-matnr.

    ASSIGN COMPONENT ‘LGORT’ OF STRUCTURE <f_out_wa> TO <f_fs1>.

    <f_fs1> = itab_sum-lgort.
    READ TABLE itab_bwart WITH KEY bwart = itab_sum-bwart .

    index = sy-tabix + 3.

    ASSIGN COMPONENT index OF STRUCTURE <f_out_wa> TO <f_fs1>.

    <f_fs1> = itab_sum-menge.
    ASSIGN COMPONENT ‘LINE_SUM’ OF STRUCTURE <f_out_wa> TO <f_fs1>.

    <f_fs1> = itab_sum-menge.
    COLLECT <f_out_wa> INTO <f_out> .

    CLEAR <f_out_wa>.

ENDLOOP.

ENDFORM.                    ” FIXDATA
*&———————————————————————*

*&      Form outdata

*&———————————————————————*

FORM outdata.

PERFORM fieldcat_init .

sla-colwidth_optimize = ‘X’.

sla-zebra             = ‘X’.

i_repid = sy-repid.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

       EXPORTING

            i_callback_program      = i_repid

            it_fieldcat             = gd_fieldcat[]

            i_save                  = ‘A’

            is_variant              = ivariant

            is_layout               = sla

            it_excluding            = i_excluding

*            i_callback_user_command = ‘USER_COMMAND’

       TABLES

            t_outtab                = itab_sum

       EXCEPTIONS

            program_error           = 1

            OTHERS                  = 2.
ENDFORM.                    ” outdata

*———————————————————————*

*       FORM fieldcat_init                                            *

*———————————————————————*

FORM fieldcat_init .

PERFORM frm_catlg_set USING: ‘WERKS’     ‘WERKS’ ‘X’ ,

                               ‘MATNR’     ‘MATNR’ ‘X’ ,

                               ‘LGORT’     ‘LGORT’ ‘X’ ,

                               ‘BWART’     ‘BWART’ ” ,

                               ‘MENGE’     ‘MENGE’ ” .

ENDFORM.                    “fieldcat_init
*———————————————————————*

*       FORM frm_catlg_set                                            *

*———————————————————————*

FORM frm_catlg_set USING p_field

                         p_text

                         p_key.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat-fieldname     = p_field.

ls_fieldcat-seltext_l     = p_text.

ls_fieldcat-key           = p_key.
IF p_field = ‘LINE_SUM’.

    ls_fieldcat-emphasize = ‘C700’.

ENDIF.

APPEND ls_fieldcat TO gd_fieldcat .

CLEAR ls_fieldcat .

ENDFORM.                    “frm_catlg_set
*&——————————————————————–*

*&      Form user_command

*&——————————————————————–*

*FORM user_command USING r_ucomm LIKE sy-ucomm

*                    rs_selfield TYPE slis_selfield.

* READ TABLE itab INDEX rs_selfield-tabindex.

* CASE r_ucomm.

*    WHEN ‘&IC1’. “双击

*

*    WHEN ‘EXIT’.

*      LEAVE PROGRAM.

* ENDCASE.

** rs_selfield-refresh = ‘X’. “自动刷新

*ENDFORM. “user_com
*———————————————————————*

*       FORM outdata2                                                 *

*———————————————————————*

FORM outdata2.

PERFORM fieldcat_init2 .
sla-colwidth_optimize = ‘X’.

sla-zebra             = ‘X’.

i_repid = sy-repid.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

       EXPORTING

            i_callback_program      = i_repid

            it_fieldcat             = gd_fieldcat[]

            i_save                  = ‘A’

            is_variant              = ivariant

            is_layout               = sla

            it_excluding            = i_excluding

       TABLES

            t_outtab                = <f_out>

       EXCEPTIONS

            program_error           = 1

            OTHERS                  = 2.

ENDFORM.                    ” outdata
*———————————————————————*

*       FORM fieldcat_init2                                           *

*———————————————————————*

FORM fieldcat_init2 .

CLEAR c .

PERFORM frm_catlg_set USING: ‘WERKS’   ‘WERKS’ ‘X’ ,

                               ‘MATNR’   ‘MATNR’ ‘X’ ,

                               ‘LGORT’   ‘LGORT’ ‘X’ .

LOOP AT hs_bwart .

    c = c + 1.

    CONCATENATE ‘MENGE’ c INTO txt.

    PERFORM frm_catlg_set USING: txt hs_bwart-bwart ” .

ENDLOOP.

PERFORM frm_catlg_set USING: ‘LINE_SUM’ ‘SUM’ ” .

ENDFORM.                    “fieldcat_init
*———————————————————————*

*       FORM creat_itab_out                                           *

*———————————————————————*

FORM creat_itab_out.
CLEAR c.

PERFORM build_itab_stru USING: ‘WERKS’ ‘MSEG’ ‘WERKS’ ,

                                 ‘MATNR’ ‘MSEG’ ‘MATNR’ ,

                                 ‘LGORT’ ‘MSEG’ ‘LGORT’ .
LOOP AT hs_bwart.

    c = c + 1.

    CONCATENATE ‘MENGE’ c INTO txt.

    PERFORM build_itab_stru USING: txt ‘MSEG’ ‘MENGE’ .

ENDLOOP.
PERFORM build_itab_stru USING: ‘LINE_SUM’ ‘MSEG’ ‘MENGE’ .
CALL METHOD cl_alv_table_create=>create_dynamic_table

               EXPORTING

                  it_fieldcatalog = ifc

               IMPORTING

                  ep_table        = dy_out.

ASSIGN dy_out->* TO <f_out>.

CREATE DATA dy_out_wa LIKE LINE OF <f_out>.

ASSIGN dy_out_wa->* TO <f_out_wa>.

ENDFORM.
*———————————————————————*

*       FORM build_itab_stru                                          *

*———————————————————————*

FORM build_itab_stru USING fdname ref_t ref_f.

xfc-fieldname = fdname .

xfc-ref_table = ref_t.

xfc-ref_field = ref_f.

APPEND xfc TO ifc.

ENDFORM.

转载于:https://www.cnblogs.com/johnson_yao/archive/2011/09/09/2172238.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110556.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 国内NFT平台及玩法一览[通俗易懂]

    国内NFT平台及玩法一览[通俗易懂]2021年被称为NFT的“元年”,互联网巨头、各大企业、艺术家、明星纷纷入局NFT,屡创新高的NFT价格更是让其成为大众关注焦点。此推出NFT系列专题研究,盘点和总结NFT的发行市场、平台背景、投融资状况、市场热点、政策监管等相关内容,帮助读者对NFT市场有更全面地了解。随着国外NFT风潮的火热,国内风潮总算是姗姗来迟,入局NFT的选手也是越来越多。NFT发行平台是为NFT提供发行、交易等服务的平台,根据平台的所在地,NFT发行平台能够被分为国内和国外两个市场。本文主要对于国内NFT发行平台.

  • getmethod设置参数_nginx get参数

    getmethod设置参数_nginx get参数java.lang.Class中的getMethod(Stringname,Class…parameterTypes)方法后面的parameterTypes是传入的想要获取的方法的参数。是为了区分重载的方法。

  • java Graphics2D类

    Java 2D拥有强大的二维图形处理能力,这些功能主要是由Graphics2D类来完成的,该类是Graphics类的一个子类。它的特点是把所绘的图形当成一个对象来处理,绘制前先创建对象。绘制2D直线调用格式:先创建2D线形对象:Line2D line=new Line2D.Double(double x1,double y1,double x2,double y2);然

  • 最全的 Charles 抓包工具详解「建议收藏」

    最全的 Charles 抓包工具详解「建议收藏」本文介绍了详细介绍了Charles的HTTP/HTTPS抓包功能,其中包括模拟慢网速、断电功能、Compose功能、重写功能、映射功能、Repeat功能、以及Android7.0抓包问题

  • pod Evicted的状态究竟是何人所为

    pod Evicted的状态究竟是何人所为微信公众号:运维开发故事,作者:姜总背景今天发现好多pod的状态都是Evicted,然后我没有监控的权限,本来想看看grafana上监控图是否出现了特殊情况,无奈没权限看。因为我发现pod出现大量的Evicted状态的时候,查看pod所在的node节点,距离当时发生Evicted的时间已经是7小时之久了。因此可能会存在一种原因:发生了Evicted的时候的确磁盘已经超过默认的kubelet的资源预留参数了。但是问题发生后,触发了阈值,已经回收了磁盘空间,导致我看的时候磁盘空间已经恢复。在每个K.

  • 平台卡盟 平台卡盟_卡盟主站源码下载

    平台卡盟 平台卡盟_卡盟主站源码下载源码介绍:该源码对接宝塔API实现秒搭建主站功能,包括分站开通等都无需人工操作源码价值:****.**¥我也不知道值多少钱,反正修了很久才对接好宝塔接口跟各种问题,搞了好多天,时间长达3个月,不过不是连续修2个月,反正开始搞到现在搞了3个月多吧没有接好支付通道,想要运营的可以找我对接或者找别人对接安装说明服务器系统:Linux+Centos7.x+宝塔亲测环境:Nginx1.1…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号